python - Run a whole Twisted application in multiple processes -


i know limitations of twisted multiprocess applications, question different. not trying run server or client using multiple processes. have running application takes number of directories , performs operations on them. want divide work in chunks, spawning process same application each subdirectory. can running application multiple times shell , passing different subdirectory argument each time.

in main have like:

from multiprocessing import pool ... p = pool(num_procs) work_chunks = [work_chunk] * len(configs) p.map(run_work_chunk, zip(work_chunks, configs)) p.close() p.join() 

where:

def run_work_chunk((work_chunk, config)):     twisted.internet import reactor     d = work_chunk.configure(config)      d.addcallback(lambda _: work_chunk.run())     d.adderrback(handlelog)     print "pid=", getpid(), "reactor=", id(reactor)     reactor.run()     return  class workchunk(object):     ...     def run(self):         # stuff         ...         reactor.stop() 

let's num_procs 2, output like:

pid=2 reactor=140612692700304

pid=6 reactor=140612692700304

and can't see output workers working in other chunks.

the problem when reactor.stop() called, stops reactors because each process uses same reactor. thought when spawning new process, stack copied, in case copying reference reactor, processes use same reactor object.

is there way instantiate different reactor object each process? (as if different process , not child process)

is there way instantiate different reactor object each process? (as if different process , not child process)

if mean process best way run code multiple times (and/or fork/exec create new processes initial process).

there no magic managing multiple reactors, done same way run multiple programs in other context.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -