[pypy-dev] PyPy threads

Rene Nejsum rene at pylots.com
Sun Apr 8 14:31:34 EDT 2018


I have been running some test on PyPy3 1) hope someone can confirm/explain this:

If PyPy is running a tight loop in a thread, other threads will not be run/scheduled?

The example:

I am running factorial(200000) in a thread: 2)
class MathActor(Actor):
    def factorial(self, n):
        logger.debug("factorial(%d)" % n)
        i = n
        while i > 1:
            i -= 1
            n *= i
        logger.debug("fact done...")
        return n

On pypy3 all other threads (100+) seams to stop/block, while factorial() is executing, the log:

180404 142203.094 INFO  [worker:3:WorkerTask] timeout(): 4
180404 142203.094 INFO  [worker:3:WorkerTask] Starting math job
*180404 142203.095 DEBUG factorial(200000)*
*180404 142234.486 DEBUG fact done…*
180404 142234.487 INFO  [netclient:9:EchoClientTask] Client: timeout: 127.0.0.1:5050
180404 142234.488 INFO  [worker:3:WorkerTask] timeout(): 5
180404 142238.257 INFO  [worker:3:WorkerTask] result from factorial, has 973351 digits

I suspect the JIT sits in a very tight loop? But the OS should schedule other threads? Event though the don’t do I/O? Most of them doing queue.get(timeout=5) waiting for new messages. I did a quick google, but could not find anything about this on pypy3.


On cpython3 3) the other threads seams to run while the factorial thread is running

180404 142502.124 INFO  [netclient:9:EchoClientTask] Client received: 'From Server count: 4'
180404 142506.494 INFO  [worker:3:WorkerTask] timeout(): 4
180404 142506.494 INFO  [worker:3:WorkerTask] Starting math job
*180404 142506.495 DEBUG factorial(200000)*
180404 142507.135 INFO  [netclient:9:EchoClientTask] Client: timeout: 127.0.0.1:5050
180404 142507.368 INFO  [netclient:9:EchoClientTask] Client received: 'From Server count: 5'
180404 142511.506 INFO  [worker:3:WorkerTask] timeout(): 5
180404 142511.519 INFO  [worker:3:WorkerTask] setting value for long_work()....
180404 142511.540 INFO  [client3:6:ClientTask] Wait: got 3 = 42
180404 142511.546 INFO  [client3:6:ClientTask] Worker Task done: Good work...
180404 142512.386 INFO  [netclient:9:EchoClientTask] Client: timeout: 127.0.0.1:5050
180404 142512.598 INFO  [netclient:9:EchoClientTask] Client received: 'From Server count: 6'
180404 142516.538 INFO  [worker:3:WorkerTask] timeout(): 6
180404 142516.548 INFO  [client3:6:ClientTask] Worker Task done: Good work...
180404 142517.616 INFO  [netclient:9:EchoClientTask] Client: timeout: 127.0.0.1:5050
180404 142517.776 INFO  [netclient:9:EchoClientTask] Client received: 'From Server count: 7'
*180404 142520.666 DEBUG fact done…*
180404 142521.554 INFO  [worker:3:WorkerTask] timeout(): 7
180404 142535.265 INFO  [netclient:9:EchoClientTask] Client: timeout: 127.0.0.1:5050
180404 142535.268 INFO  [worker:3:WorkerTask] result from factorial, has 973351 digits

br
/Rene


1) pypy3 installed with brew
Python 3.5.3 (3f6eaa010fce78cc7973bdc1dfdb95970f08fed2, Jan 13 2018, 18:14:01)
[PyPy 5.10.1 with GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]

2) https://github.com/pylots/pyworks.git <https://github.com/pylots/pyworks.git>

3) python3
Python 3.6.5 (default, Mar 30 2018, 06:41:53)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin

4) HW
MacBook (Retina, 12-inch, 2017)
1,4 GHz Intel Core i7 (dual core)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20180408/3539094d/attachment.html>


More information about the pypy-dev mailing list