Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>multiprocessing</code> has limited support for <a href="http://docs.python.org/2/library/multiprocessing.html#sharing-state-between-processes" rel="nofollow">implicitly shared objects</a>, which can even share lists and dicts.</p> <p>In general, <code>multiprocessing</code> is <a href="http://docs.python.org/2/library/multiprocessing.html#all-platforms" rel="nofollow">shared-nothing</a> (after the initial fork) and relies on explicit communication between the processes. This adds overhead (how much really depends on the kind of interaction between the processes), but neatly avoids a lot of the pitfalls of multithreaded programming. The high-level building blocks of <code>multiprocessing</code> favor master/slave models (esp. the <a href="http://docs.python.org/2/library/multiprocessing.html#module-multiprocessing.pool" rel="nofollow">Pool class</a>), with masters handing out work items, and slaves operating on them, returning results.</p> <p>Keeping state in sync across several processes may, depending how often they change, incur a prohibitive overhead.</p> <p><strong>TL;DR</strong>: It can be done, but probably shouldn't.</p> <pre><code>import time, multiprocessing class Test(multiprocessing.Process): def __init__(self, manager): super().__init__() self.quit = manager.Event() self.dict = manager.dict() def stop(self): self.quit.set() self.join() def run(self): self.dict['item'] = 0 while not self.quit.is_set(): time.sleep(1) self.dict['item'] += 1 m = multiprocessing.Manager() t = Test(m) t.start() for x in range(10): time.sleep(1.2) print(t.dict) t.stop() </code></pre> <p>The <code>multiprocessing</code> examples show how to create proxies for more <a href="http://docs.python.org/2/library/multiprocessing.html#examples" rel="nofollow">complicated objects</a>, which should allow you to implement the tree structure in your question.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload