twistedtwisted.application

Twisted: spawn an application daemon from another application daemon


I have a Twisted application daemon which is started by twistd. This daemon acts as a daemon manager to manage many other Twisted application daemons. I can send the manager a "new" command via TCP and the manager should spawn(fork) another Twisted application daemon. My question is how can I do that? After fork, I think I should stop the manager's reactor loop, close opened file descriptors(logging file), then run the new Twisted application daemon. I want to know the details of how to do these things properly.


Solution

  • You should use the reactor's spawnProcess method. See http://twistedmatrix.com/documents/current/core/howto/process.html for details on its use.

    You should not fork or do any of those other steps yourself. They are difficult to do correctly, and spawnProcess already does them for you.

    If you're curious about how these things are done, you can browse the various implementations.