Re: odd runtime error



On Wed, Dec 1, 2010 at 4:59 PM, Chris Rebert <clp2@xxxxxxxxxxxx> wrote:
On Wed, Dec 1, 2010 at 4:49 PM, David Brown <dmlb2000@xxxxxxxxx> wrote:
So I'm not subscribed to python-list but would like to get an answer
to my question. I've made a small test program that dumps a
RuntimeError and I'd like to know why.

$ python test2.py
doing stuff
Traceback (most recent call last):
 File "test2.py", line 3, in <module>
   import test
RuntimeError: not holding the import lock
child 3693 exited with 256
$

Here's the setup, there's two files test.py and test2.py

$ cat test.py
#!/usr/bin/python

import os, sys

if os.fork() == 0:
       print "doing stuff"
       sys.exit()

print "child %d exited with %d" % os.wait()

It's *quite* strange for a module that's being imported to execute a
fork() in its body; this is almost assuredly the cause of the
RuntimeError. Why are you fork()ing in an importable module in the
first place?

Well, to be specific the fork isn't the cause of the RuntimeError, the
sys.exit() causes the runtime error. I agree that forking in a module
is bad coding practice and I'm working with the developer to help him
understand why that's bad. If that makes sense. However, knowing why
sys.exit() is producing a RuntimeError on some versions of python and
not others also more interesting a question.

Thanks,
- David Brown

Cheers,
Chris
--
http://blog.rebertia.com

.



Relevant Pages

  • Re: odd runtime error
    ... I've made a small test program that dumps a ... RuntimeError and I'd like to know why. ... $ python test2.py ... $ cat test.py ...
    (comp.lang.python)
  • Re: odd runtime error
    ... I've made a small test program that dumps a ... RuntimeError and I'd like to know why. ... Traceback: ... Why are you forking in an importable module in the ...
    (comp.lang.python)
  • Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?
    ... Python object trees consist only of dicts and lists as far as variable non-atomic datastructures are concerned. ... AFAIK about the current Python implementation: This RuntimeError is only thrown "during true Iteration over dict/list, when the number of items changes". ...
    (comp.lang.python)
  • odd runtime error
    ... I've made a small test program that dumps a ... RuntimeError and I'd like to know why. ... $ cat test2.py ... I was more curious about what this behavior is and why python is doing ...
    (comp.lang.python)
  • Re: odd runtime error
    ... I've made a small test program that dumps a ... | RuntimeError and I'd like to know why. ... | I was more curious about what this behavior is and why python is doing ... Python takes a lock during imports - this stops multiple threads ...
    (comp.lang.python)