Mix Python Twisted with multiprocessing?

Twisted has its own event-driven way of running subprocesses which is (in my humble, but correct, opinion) better than the multiprocessing module. The core API is spawnProcess, but tools like ampoule provide higher-level wrappers over it.

If you use spawnProcess, you will be able to handle output from subprocesses in the same way you’d handle any other event in Twisted; if you use multiprocessing, you’ll need to develop your own queue-based way of getting output from a subprocess into the Twisted mainloop somehow, since the normal callFromThread API that a thread might use won’t work from another process. Depending on how you call it, it will either try to pickle the reactor, or just use a different non-working reactor in the subprocess; either way it will lose your call forever.

Leave a Comment