3 ms·
>Why didn't they just use a single global loop? Sorta like javascript and golang. I imagine the problem is, that neither JS or Golang have to deal with, is Pyt
by nemothekid 6y ago
>Why didn't they just use a single global loop? Sorta like javascript and golang.
I imagine the problem is, that neither JS or Golang have to deal with, is Python supports plain old threads. If you have a single global event loop, and then you try execute a future what should happen?
1. Should every every thread have its own loop? Then how would you send futures to another thread.
2. Should the global loop only exist on a single thread? Then you would have to pay a synchronization tax every time you pushed a task to the loop.
Not saying the Python solution is 100% right (I've only thought about it for 5 minutes), but I can see how being compatible with threads has caused this situation. I believe the default now is you don't have to think about loops, and Python does the right thing for 99% of use cases.
- jordic 6y agoIf you need to do CPU bound computations use a thread pool.
- vazamb 6y agoWhy this being downvoted: You need to use a process pool in Python, thread pools are for I/O bound tasks and cannot use more than 1 core.
- nemothekid 6y agoI didn't downvote him, but his response isn't at all relevant to what was being discussed. I was discussing the API design of asyncio and how they had to add the "loop" parameter to ensure the reactor would be thread safe by default.