g0blin Bringing together art & technology


Breaking out of subprocess

While creating a wrapper for the Mincraft server, I came across a small problem. In order to execute the JAR file from within the Python script I needed to fire it up as a subprocess. Unfortunately, Python kills off subprocesses automatically before closing itself (I'm not sure if this is infact the default behaviour of Python or a behaviour caused by using the CherryPy library). This would not do - Power to the Process!

In order to get around this problem, I needed to break my threads out of the Python process, so that proceeding to exit the Python process would not immediately kill off the subprocesses. To do this successfully across both Linux and Windows we make use of a couple of different methods.



For Windows, we make use of the 'creationflags' argument - and for Linux we make use of the 'preexec_fn' argument. Both have the same effect of breaking the subprocess out of its parent. Now threads will not stop until they are damn well ready - i.e. when they reach the end of their run() function.

Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.