<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=utf-8" http-equiv=Content-Type><!-- flashmail style begin -->
<STYLE type=text/css>
body {border-width:0;margin:0}
img {border:0;margin:0;padding:0}
</STYLE>
<BASE target=_blank><!-- flashmail style end -->
<META name=GENERATOR content="MSHTML 11.00.10240.16603"></HEAD>
<BODY
style="BORDER-LEFT-WIDTH: 0px; FONT-SIZE: 10.5pt; FONT-FAMILY: 微软雅黑; BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; COLOR: #000000; MARGIN: 12px; LINE-HEIGHT: 1.5; BORDER-TOP-WIDTH: 0px"
marginheight="0" marginwidth="0">
<DIV>Thanks for the response. Should I put it directly in the bug
tracker?</DIV>
<DIV> </DIV>
<DIV>FYI, I've located the reason to be the incompatibility with python-daemon
(or rather the standard unix-daemon behavior) and
PyPy <STRONG>posix.urandom</STRONG> implementation. </DIV>
<DIV> </DIV>
<DIV>It seems that in PyPy 4.0.1, when module <STRONG>random</STRONG> loaded, a
file descriptor is created on /dev/urandom. I think PyPy implementation use the
shared descriptor to read from /dev/urandom. Sadly when python-daemon fork the
process and turns it into an unix daemon, it closes all the currently open file
descriptors. After that all os.urandom calls failed with OSError. I think maybe
the other functions of Random class is also using the file descriptor in C
code and just never detects if the return value is 0, and causes the
dead loop.</DIV>
<DIV> </DIV>
<DIV>I think the problem will be solved if the implementation re-open
the handle when it is closed somehow.</DIV>
<DIV> </DIV>
<DIV>multiprocessing is using random internally. Also there are lots of
other modules using random, like email etc. The dead loop occurs when you use
any of the libraries in a daemon.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; COLOR: #c0c0c0"
align=left>2015-12-23
<HR id=SignNameHR
style="BORDER-TOP: #c0c0c0 1px solid; HEIGHT: 1px; BORDER-RIGHT: 0px; WIDTH: 122px; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px"
align=left>
<SPAN id=_FlashSignName>hubo</SPAN> </DIV>
<HR
style="BORDER-TOP: #c0c0c0 1px solid; HEIGHT: 1px; BORDER-RIGHT: 0px; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px">
<BLOCKQUOTE id=ntes-flashmail-quote
style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; PADDING-LEFT: 0px; MARGIN-LEFT: 0px">
<DIV><STRONG>发件人:</STRONG>Maciej Fijalkowski <fijall@gmail.com></DIV>
<DIV><STRONG>发送时间:</STRONG>2015-12-23 19:35</DIV>
<DIV><STRONG>主题:</STRONG>Re: [pypy-dev] Dead loop occurs when using
python-daemon and multiprocessing together in PyPy 4.0.1</DIV>
<DIV><STRONG>收件人:</STRONG>"hubo"<hubo@jiedaibao.com></DIV>
<DIV><STRONG>抄送:</STRONG>"pypy-dev"<pypy-dev@python.org></DIV>
<DIV> </DIV>
<DIV>
<DIV dir=ltr>Hi hubo
<DIV><BR></DIV>
<DIV>Can you put it as a bug report? Those things get easily lost on the
mailing list (and sadly I won't look at it right now, multiprocessing scares
me)</DIV></DIV>
<DIV class=gmail_extra><BR>
<DIV class=gmail_quote>On Wed, Dec 23, 2015 at 12:03 PM, hubo <SPAN
dir=ltr><<A href="mailto:hubo@jiedaibao.com"
target=_blank>hubo@jiedaibao.com</A>></SPAN> wrote:<BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex"><U></U>
<DIV
style="BORDER-LEFT-WIDTH: 0px; FONT-SIZE: 10.5pt; FONT-FAMILY: 微软雅黑; BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; COLOR: #000000; MARGIN: 12px; LINE-HEIGHT: 1.5; BORDER-TOP-WIDTH: 0px"
marginheight="0" marginwidth="0"><U></U>
<DIV>Hello devs,</DIV>
<DIV> </DIV>
<DIV>A (possible) dead loop is found when I use python-daemon and
multiprocessing together in PyPy 4.0.1, which does not appear in Python(2.6
or 2.7). Also it does not appear in earlier PyPy versions (2.0.2)</DIV>
<DIV> </DIV>
<DIV><STRONG>Reproduce</STRONG>:</DIV>
<DIV> </DIV>
<DIV>First install python-daemon:</DIV>
<DIV>pypy_pip install python-daemon</DIV>
<DIV> </DIV>
<DIV>Use the following test script (also available in attachment):</DIV>
<DIV> </DIV>
<DIV>#!/usr/bin/pypy<BR>import daemon<BR>import multiprocessing<BR>def
test():<BR> q = multiprocessing.Queue(64)<BR>if __name__
== '__main__':<BR> with
daemon.DaemonContext():<BR>
test()</DIV>
<DIV> </DIV>
<DIV>When executing the script with pypy:</DIV>
<DIV>pypy test.py</DIV>
<DIV> </DIV>
<DIV>The background service does not exit, and is consuming 100% CPU:</DIV>
<DIV>ps aux | grep pypy<BR>root 7769
99.1 0.5 235332 46812 ?
R 17:52 2:09 pypy
test.py<BR>root 7775 0.0 0.0
103252 804 pts/1 S+
17:54 0:00 grep pypy</DIV>
<DIV> </DIV>
<DIV><IMG src="cid:flashmail$J3es7lB5$1450871683__0@nmmp"></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Executing the script with python:</DIV>
<DIV>python2.7 test.py</DIV>
<DIV>And the background service normally exits.</DIV>
<DIV> </DIV>
<DIV><STRONG>Environment:</STRONG></DIV>
<DIV>I'm using CentOS 6.5, with portable PyPy distribution for linux (<A
href="https://bitbucket.org/squeaky/portable-pypy/downloads/pypy-4.0.1-linux_x86_64-portable.tar.bz2"
target=_blank>https://bitbucket.org/squeaky/portable-pypy/downloads/pypy-4.0.1-linux_x86_64-portable.tar.bz2</A>)</DIV>
<DIV>I run the script on system built-in python (python 2.6.6), a compiled
CPython (2.7.11), and pypy from epel-release(pypy 2.0.2, python 2.7.2), and
the problem does not appear. Though the compiled CPython is 2.7.11 and PyPy
4.0.4 is python 2.7.10, I think that does not matter much.</DIV>
<DIV> </DIV>
<DIV>Please contact if you have any questions or ideas.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; COLOR: #c0c0c0">
<DIV align=left>2015-12-23</DIV>
<HR
style="BORDER-TOP: #c0c0c0 1px solid; BORDER-RIGHT: 0px; WIDTH: 122px; BORDER-BOTTOM: 0px; MIN-HEIGHT: 1px; BORDER-LEFT: 0px"
align=left>
<SPAN class=HOEnZb><FONT color=#888888><SPAN>hubo</SPAN>
</FONT></SPAN></DIV><U></U></DIV><BR>_______________________________________________<BR>pypy-dev
mailing list<BR><A
href="mailto:pypy-dev@python.org">pypy-dev@python.org</A><BR><A
href="https://mail.python.org/mailman/listinfo/pypy-dev" rel=noreferrer
target=_blank>https://mail.python.org/mailman/listinfo/pypy-dev</A><BR><BR></BLOCKQUOTE></DIV><BR></DIV></DIV></BLOCKQUOTE></BODY></HTML>