I can only reproduce the OSError problem. Maybe the CPU
100% is not really a dead lock, but rather some kind of automatic crash report?
Although it is quite easy to crash the program with os.urandom, it
only stops responding when the crash happens in system libraries like
multiprocessing or email.
The posix.urandom problem is quite easy to reproduce:
#!/usr/bin/pypy
import os
os.urandom(16)
def
test():
print repr(os.urandom(16))
import
daemon
import sys
if __name__ == '__main__':
with
daemon.DaemonContext(initgroups=False,
stderr=sys.stderr,stdout=sys.stdout):
test()
(stderr and stdout is kept open to show console messages in the daemon.
initgroups=False is a workaround on python-daemon not working in
Python2.6)
Or, with module random:
#!/usr/bin/pypy
import random
def test():
random.Random()
import daemon
import sys
if __name__ ==
'__main__':
with daemon.DaemonContext(initgroups=False,
stderr=sys.stderr,stdout=sys.stdout):
test()
And when run scripts with pypy:
pypy test3.py
it crashes with OSError:
Traceback (most recent call last):
File "test2.py", line 13, in
<module>
test()
File "test2.py", line 6,
in test
random.Random()
File
"/opt/pypy-4.0.1-linux_x86_64-portable/lib-python/2.7/random.py", line 95, in
__init__
self.seed(x)
File
"/opt/pypy-4.0.1-linux_x86_64-portable/lib-python/2.7/random.py", line 111, in
seed
a = long(_hexlify(_urandom(2500)), 16)
OSError:
[Errno 9] Bad file descriptor
It is still not clear why it causes dead loop (or long-time no responding)
in multiprocessing (should have thrown an ImportError) and the exact condition
for the file descriptor of /dev/urandom appears (just call os.urandom and import
random does not reproduce the result), but I believe it is definitely
linked to the problem.
2015-12-23
hubo
发件人:Maciej Fijalkowski <fijall@gmail.com>
发送时间:2015-12-23 20:07
主题:Re: Re: [pypy-dev] Dead loop occurs when using
python-daemon and multiprocessing together in PyPy 4.0.1
收件人:"hubo"<hubo@jiedaibao.com>
抄送:"pypy-dev"<pypy-dev@python.org>
That's very interesting, can you produce a standalone example
that does not use multiprocessing? That would make it much easier to fix the
bug (e.g. os.fork followed by os.urandom failing)