On 4/19/07, Kelly Yancey <[EMAIL PROTECTED]> wrote:
> Shannon -jj Behrens さんは書きました:
> > On 4/18/07, Ian Bicking <[EMAIL PROTECTED]> wrote:
> >>
> >> John_Nowlan wrote:
> >> > I do the following, and then get the following loop until I ctl-c
> >> it, is
> >> > this a bug or am I doing something stupid?
> >> >
> >> > {x:174} paster serve --daemon --monitor-restart development.ini
> >> > Starting subprocess with monitor parent
> >> > Entering daemon mode
> >> > -------------------- Restarting --------------------
> >> > Entering daemon mode
> >> > -------------------- Restarting --------------------
> >> > Entering daemon mode
> >> > -------------------- Restarting --------------------
> >> > Entering daemon mode
> >> > -------------------- Restarting --------------------
> >> > ^C^C caught in monitor process
> >> > {x:175}
> >>
> >> Ah, I see... the daemonizing happens after the monitor, not before the
> >> monitor. So as far as the monitor is concerned, the subprocess is
> >> constantly dying (since during daemonization the subprocess spawns
> >> another process then dies). Daemonizing should happen before the
> >> monitor process.
> >>
> >> I'm having problems with monitor anyway, I'm going to have to look at it
> >> more closely (killing the monitor currently doesn't kill the subprocess).
> >
> > My buddy, Kelly Yancey, is a rock start at this kind of stuff ;) I
> > know he's thinking of using Paste, so I'll cc him.
> >
> > Best Regards,
> > -jj
> >
>
> Thanks for the plug, J.J. :)
>
> Since the child processes are currently running in their own sessions
> and process groups (due daemonizing them after spawn) I would venture
> that the cause is simply that signals aren't propogated across process
> groups. Moving the daemonization to before the subprocess is spawned
> should fix the problem (since the children would be in the same process
> group as the daemonized monitor process).
>
> That said, I had a similar problem quite some time back with
> subprocesses not receiving signals so they would not shut down when the
> parent did. In my case, I was forking the processes from C, but the
> principle is the same: exec*() under POSIX only resets signals that are
> not ignored. So if the parent ignores some signal and then forks
> another process and that process calls exec*() to load a new program
> image, the new program won't receive the ignored signal either.
> Python's os.spawn*() family of functions do exactly this fork()/exec()
> pair; I haven't looked, but I doubt they reset the signals for you
> automatically.
> Here is the C code I used to workaround the problem. In my case, I
> put it between the fork() and the exec() in my equivalent of python's
> os.spawn*(), but you can put it anywhere in the child processes' code
> for the same effect. It looks like the python signal module should make
> porting to python pretty straightforward:
>
> /*
> * Reset the child's signal handlers back to their defaults.
> * The execvp() call below resets only signals that are not
> * being ignored, hence we need this loop to get the rest.
> * XXX There has got to be a better way to do this!
> */
> for (i = 0; i < NSIG; i++)
> signal(i, SIG_DFL);
>
> Completely untested, but I would expect the logic to look like this
> in Python:
> import signal
> for i in range(signal.NSIG):
> signal.signal(i, signal.SIG_DFL)
>
> By the way, I have never found a better way to do it. :) Of course,
> all of this presumes that the parent process is setting signal's handler
> to SIG_IGN somewhere, meaning that it expects to ignore the signal, but
> you don't want the children to ignore the same signal. I haven't looked
> at the monitor code in Paste yet to know. It isn't very common that
> this is the case, but I thought I should mention it anyway.
>
> By the way, Ian, J.J. had suggested I send you a patch for issue
> (which I haven't done yet), but I found a subtle bug in Paste's
> Accept-Language parsing a couple of weeks ago. The description is in my
> blog at:
> http://kbyanc.blogspot.com/2007/04/more-i-dig-through-code-more-paste-is.html
> The fix is pretty trivial (and detailed in my blog). I'm sorry I've
> been a lazy bum and not sent you patches yet.
See!?! I told you he was a rock star! ;)
-jj
--
http://jjinux.blogspot.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---