HI list,<br><br>I found the problem guys, when I embedded python code didn't call to PyEval_InitThreads();<br>This function initialize GIL and other data structures for do a python code thread safe. I believe the python traditional ( python name_script.py ) run always a thread safe interpreter.<br>
<br>Therefore, it's normal  found best performance  in no thread safe environment and thread safe environment.<br><br>But I have a small question, if I have a typical PyObject_CallObject environment and main code don't call to PyEval_InitThreads() after Py_Initialize(), if in python code function called launch some threads this interpreter will be prepare for handle more one thread with python thread safe environment, can everybody help me ?<br>
<br>Thks<br><br><br><div class="gmail_quote">On Tue, Jun 3, 2008 at 9:58 PM, Pau Freixes <<a href="mailto:pfreixes@milnou.net">pfreixes@milnou.net</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi list,<br><br>First Hello to all, this is my and hope not end message to the list :P<br><br>This last months I have been writting a  program in c like to mod_python for embedding python language, it's a middleware for dispatch and execute python batch programs into several nodes. Now I'm writing some python program for test how scale this into several nodes and comparing with "standalone" performance. <br>

<br>I found a very strange problem with one application named md5challenge, this aplication try to calculate the max number md5 digest in several seconds, md5challenge use a simple signal alarm for stop program when time has passed. This is the code of python script<br>

<br>def handler_alrm(signum, frame):<br>    global _signal<br>    global _nrdigest<br>    global _f<br><br><br>    _signal = True<br><br>def try_me():<br>    global _nrdigest<br>    global _f<br>    global _signal<br><br>

    _f = open("/dev/urandom","r")<br>    while _signal is not True:<br>        buff = _f.read(_const_b)<br>        md5.md5(buff).hexdigest()<br>        _nrdigest = _nrdigest + 1<br><br>    if _f is not None : <br>

        _f.close()<br><br>def main( req ):<br>    global _nrdigest<br><br><br>    signal.signal(signal.SIGALRM, handler_alrm)<br>    signal.alarm(req.input['time'])  <br><br>   <br>    try_me()<br><br>    req.output['count'] = _nrdigest<br>

<br>    return req.OK<br><br><br>if __name__ == "__main__":<br>    <br>    # test code<br>    class test_req:<br>        pass<br>    <br>    req = test_req()<br>    req.input = { 'time' : 10 }<br>    req.output = { 'ret' : 0, 'count' : 0 }<br>

    req.OK = 1<br><br>    main(req)<br><br>    print "Reached %d digests" % req.output['count']<br><br><br>When I try to run this program in standalone into my Pentium Dual Core md4challenge reached 1.000.000 milion keys in 10 seconds but when i try to run this in embedded mode md5challenge reached about 200.000 more keys !!! I repeat this test many times and  always  wins  embedded mode  !!!  What's happen ?<br>

<br>Also I tested to erase read dependencies from /dev/random, and calculate all keys from same buffer. In this case embedded mode win always also, and the difference are more bigger !!!<br><br>Thks to all, can anybody help to me ?<br>
<font color="#888888">
-- <br>Pau Freixes<br>Linux GNU/User
</font></blockquote></div><br><br clear="all"><br>-- <br>Pau Freixes<br>Linux GNU/User