I had some trouble receiving a complete log from a process that receives a
TERM signal, finishes processing, completes its output, and finally exits.
When running under supervisord, I would not get the final elements in the
output log. Anything that came after the TERM signal was truncated.
I'm including the sample python file at the end of this post. If I change
the process in order to log its output instead of writing to stdout, I
receive the expected 'Exited gracefully.' message.
Examining supervisor/process.py, I believe I found the lines causing my
problem: Subprocess.drain() calls dispatcher.handle_read_event()
unconditionally. In POutputDispatcher.handle_read_event(), we see that if
there is no data to be read, the pipe is closed. (There is a note about
there not being a more accurate way to see if the child process is done with
it.)
Subprocess calls drain() from both stop(), and finish(). If I comment out
line 344, where drain() is called from Subprocess.stop(), my program behaves
as expected. I can start and stop the process, and receive 'Exited
gracefully.' as desired. drain() is still called from finish() when the
process is reaped.
Unfortunately, I don't know the full implications of the change. Is there a
more appropriate change to make? What would be a good final solution so
that output can be captured after a subprocess is passed a TERM signal?
Thanks!
Mark Kalmes
sample subprocess for illustration: (supervisord.conf set with
stopsignal=INT)
#!/usr/bin/python
# prove accepting SIGINT signal gives me the behavior I want..
from signal import *
import logging, sys, time
stopnow = False
def interrupt(signal, stack):
print "Interrupt raised"
global stopnow
stopnow = True
def uninterruptiblefunc():
for i in range(10):
print i
time.sleep(1)
signal(SIGINT, interrupt)
while not stopnow:
uninterruptiblefunc()
print "Exited gracefully."
_______________________________________________
Supervisor-users mailing list
[email protected]
http://lists.supervisord.org/mailman/listinfo/supervisor-users