[Twisted-Python] Strange twistd behaviour

I have an application ran as a twistd plugin. It spawns a "worker thread" that gets objects from Queue.Queue and runs in a "while 1: " loop. The problem I got is that when I run the application without daemonizing it (using -n switch for twistd) everything works fine, but as soon as it is run as daemon, the thread does not perform the "looping". I am bit stuck, as I don't know even where to look for possible causes... Can anybody put some light here? -- Jarek Zgoda "We read Knuth so you don't have to."

On Mon, 12 Mar 2007 15:41:04 +0100, Jarek Zgoda <jarek.zgoda@sensisoft.com> wrote:
I have an application ran as a twistd plugin. It spawns a "worker thread" that gets objects from Queue.Queue and runs in a "while 1: " loop. The problem I got is that when I run the application without daemonizing it (using -n switch for twistd) everything works fine, but as soon as it is run as daemon, the thread does not perform the "looping". I am bit stuck, as I don't know even where to look for possible causes... Can anybody put some light here?
If you are starting the thread before the process daemonizes, you might want to try starting it after daemonization instead and see if that helps. You can do this by starting the thread in the startService method of a Service. Combining forking and threading usually leads to suffering. Jean-Paul

Jean-Paul Calderone napisał(a):
If you are starting the thread before the process daemonizes, you might want to try starting it after daemonization instead and see if that helps.
You can do this by starting the thread in the startService method of a Service.
I see, I added the code for creating the thread in "after startup" event trigger and now it forks fine, thank you. -- Jarek Zgoda "We read Knuth so you don't have to."

On 03:24 pm, jarek.zgoda@sensisoft.com wrote:
Jean-Paul Calderone napisa2(a):
If you are starting the thread before the process daemonizes, you might want to try starting it after daemonization instead and see if that helps.
You can do this by starting the thread in the startService method of a Service.
I see, I added the code for creating the thread in "after startup" event trigger and now it forks fine, thank you.
You might also consider using the reactor's built-in thread support, reactor.callInThread, rather than starting your own worker thread.

Jarek Zgoda wrote:
I have an application ran as a twistd plugin. It spawns a "worker thread" that gets objects from Queue.Queue and runs in a "while 1: " loop. The problem I got is that when I run the application without daemonizing it (using -n switch for twistd) everything works fine, but as soon as it is run as daemon, the thread does not perform the "looping". I am bit stuck, as I don't know even where to look for possible causes... Can anybody put some light here?
You probably spawn the thread in the wrong process. You should make sure the thread is spawned by the reactor, e.g. by doing it from a startService method or using reactor.callWhenRunning. -Andrew.
participants (4)
-
Andrew Bennetts
-
glyph@divmod.com
-
Jarek Zgoda
-
Jean-Paul Calderone