majek/puka — pull request #24 by kung-foo (2012-09-05 08:28:13+00:00)
Title: set fcntl.FD_CLOEXEC on socket to prevent leaked handles

We had several situations where an app creates a puka connection and then later on, spawns various new processes using subprocess.Popen(). If the app crashed or was restarted, the puka socket descriptor would still be held open by the now orphaned child processes. Since the connections are still open, rabbit would not release the unacknowledged messages. Setting fcntl.FD_CLOEXEC forces the handles to be closed immediately after the fork.

Several other python projects use similar code. Tornado's ioloop (before the multi-process support) used the same technique.

Python 3.2 will change the default behavior subprocess.Popen() to close all handles.