Daemonization / Popen / pipe issue

Lee Clemens java at leeclemens.net
Sat Mar 17 03:12:14 CET 2012


Hello,

I am new to the list, have many years of Java experience but an fairly new to Python. I am hoping this is an issue caused by my  misuse of Python in a multi-threaded way, but so far no one has identified such to me.

I have a multi-threaded application, each thread has an instance of a class which calls Popen. The command(s) being executed (shell=True) include pipes. The errors I have seen involve "broken pipe" and unexepected output (as demonstrated in the test case).

This issues only seem to occur when the application is "daemonized", using a double-fork and os.dup2, as shown here:
http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/

I have provided a test-case here: https://gist.github.com/2054194

Please test how flipping DAEMONIZE between True and False yield different results.

I have used this on Red Hat/CentOS/Fedora using Python 2.6.x (latest) and 2.7.1 and on Solaris with 2.6.4.

I know it's a bit long, but I have added comments to explain where the oddities appear and how it is called (fairly straight-forward multi-threaded). Please keep in mind this is a test-case based on a much larger application - I understand a lot of pieces included here are not necessary in this case.

Any assistance/advice would be greatly appreciated.

Thanks,
Lee




More information about the Python-list mailing list