Note that there are some explanatory texts on larger screens.

plurals
  1. POWith python.multiprocessing, how do I create a proxy in the current process to pass to other processes?
    primarykey
    data
    text
    <p>I'm using the <code>multiprocessing</code> library in Python. I can see how to define that objects <em>returned</em> from functions should have proxies created, but I'd like to have objects in the current process turned into proxies so I can pass them as parameters.</p> <p>For example, running the following script:</p> <pre><code>from multiprocessing import current_process from multiprocessing.managers import BaseManager class ProxyTest(object): def call_a(self): print 'A called in %s' % current_process() def call_b(self, proxy_test): print 'B called in %s' % current_process() proxy_test.call_a() class MyManager(BaseManager): pass MyManager.register('proxy_test', ProxyTest) if __name__ == '__main__': manager = MyManager() manager.start() pt1 = ProxyTest() pt2 = manager.proxy_test() pt1.call_a() pt2.call_a() pt1.call_b(pt2) pt2.call_b(pt1) </code></pre> <p>... I get the following output ...</p> <pre><code>A called in &lt;_MainProcess(MainProcess, started)&gt; A called in &lt;Process(MyManager-1, started)&gt; B called in &lt;_MainProcess(MainProcess, started)&gt; A called in &lt;Process(MyManager-1, started)&gt; B called in &lt;Process(MyManager-1, started)&gt; A called in &lt;Process(MyManager-1, started)&gt; </code></pre> <p>... but I want that final line of output coming from <code>_MainProcess</code>. </p> <p>I could just create another Process and run it from there, but I'm trying to keep the amount of data that needs to be passed between processes to a minimum. The documentation for the <code>Manager</code> object mentioned a <code>serve_forever</code> method, but it doesn't seem to be supported. Any ideas? Does anyone know?</p>
    singulars
    1. This table or related slice is empty.
    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. 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