python - How to share object tree with process fork? -


I do not have much experience with multithreading, and I'm trying to get something like work below:

  Process class node from multiprocessing import: def __init __ (self): self. Children = {} class test (define): def __init __ (self, tree): super () .__ init (__) self.tree = tree DRF (own): # infinite loop which does the stuff for the tree itself. Tree. Children [1] = node () self.tree.children [2] = node () x = node () t = test (x) t. start () print (xcand) # random access to tree   

I realize that it should not work for very sensible reasons (and not) but I'm not sure how it works to to mention the documentation While doing so, it seems that I need to do something with the manager and proxy, but I honestly do not know this Where to start from, or what exactly i want to do Can someone provide an example of the above mentioned?

multiprocusing is limited

In general, The code is> multiprocessing (after the initial fork) and depends on the clear communication between the processes. It depends on the overhead (how much actually depends on the interplay between processes), but avoids too much damage to multi-functional programming. Follow the High Level Building Blocks Master / Slow Model (APP) of Multiprocessing , the owner who hand over the work items and the slaves working on them, the results are returning.

TL; DR : It can be done, but probably should not be.

P>

  import time, multiprocessing class test (multiprocessing. Process): def __init __ (self, manager): super () .__ init __ () self. Quit = manager.Event () self.dict = manager Dict (def def (self): self.quit.set () self.join () Def run (self): self.dict ['item'] = 0 while Self.quit.is_set (): time.sleep (1) self.dict ['item'] + = 1m = multi processing Manager () T = (x) range (10) for x (m) t. Start (): time.sleep (1.2) print (T.Dict) T.stop ()   

example multiprocessing examples show how to proxy for more To create, which will allow you to implement tree structure in your question. / P>

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -