Handling a Fork
On Posix systems (e.g. GNU/Linux) Python includes the ability to fork (”A fork, when applied to computing occurs when a process creates a copy of itself, which then acts as a ‘child’ of the original process, now called the ‘parent’.” - Wikipedia).
By default the debugger will pause (break) the debuggee when it identifies that a fork is about to be attempted. At that point you may choose if you would like the debugger to continue debugging the parent or the child process.
To debug the child process type ‘fork child‘ at the console, and then request the debugger to continue.
The console ‘fork‘ command accepts the following arguments: child, parent, auto, manual. With no arguments the console ‘fork’ command returns the current state. Type ‘help fork‘ at the console for more information.
Limitations
On some Posix OS such as FreeBSD, Stepping into the child fork can result in termination of the child process since the debugger uses threading for its operation and on these systems threading and forking can conflict.
Winpdb - A Platform Independent Python Debugger
Just after entering ‘fork child’ and resuming, in the server I get:
Exception in thread __worker_target:
Traceback (most recent call last):
File “/usr/local/lib/python2.6/threading.py”, line 525, in __bootstrap_inner
self.run()
File “/var/tmp/bin/rpdb2.py”, line 4570, in run
threading.Thread.run(self)
File “/usr/local/lib/python2.6/threading.py”, line 477, in run
self.__target(*self.__args, **self.__kwargs)
File “/var/tmp/bin/rpdb2.py”, line 9357, in __worker_target
self.m_lock.release()
File “/usr/local/lib/python2.6/threading.py”, line 136, in release
raise RuntimeError(”cannot release un-aquired lock”)
RuntimeError: cannot release un-aquired lock
Am going to try putting a catch block around that stmt.
No joy with that. Client is WinXP, server is CentOS release 5 (Final). Both on Python 2.6. Any ideas welcome.
OK, I’ve worked around the issue by using the info from the Embedded Debugging link on the right, e.g.:
pid = os.fork()
if pid > 0:
os.waitpid(pid, 0)
else:
if os.environ.get(’DEBUG_RPDB2′):
sys.path.append(’/var/tmp/bin’)
import rpdb2;
rpdb2.start_embedded_debugger(’test’, fAllowRemote = True)
# rest of child process follows here