6 ms·
This looks great. I wish python would have made the event loop generally more transparent to the end user. Why didn't they just use a single global loop? Sorta
by parhamn 6y ago
This looks great. I wish python would have made the event loop generally more transparent to the end user. Why didn't they just use a single global loop? Sorta like javascript and golang. It would have been more pythonic too. Anyone doing heavier context switching could've had their own loop management.
Making the event loop self-managed added a ton of clunkiness in aio apis (use-your-own-loop, loop lifetime management, etc) and becomes mentally complex for newcomers. Theres also the issue that these huge aio frameworks rewriting the same TCP clients have emerged only differentiated by their loop management patterns.
- bluedays 6y agoThe more time I spend with Python the more reasons I find to hate it. However, it's still my main language. Everything I end up making just ends up being written in Python because that's the language I know the best. I could learn another language, and I have learned other languages, but Python seems to be the language that mentally clicks with me the most. I think it's because it's the first language I learned. Suffice to say, there are so many things wrong with Python and they're all compromises that were made to appeal to wider audience. Unfortunately, I don't think that the "wider audience" is those who are looking for concurrency.
- maallooc 6y agoMe too. As I know more and more about languages and computers, the more I hate it but I end up doing 85% of my projects because with it I can focus on ideas, not implementation details.
- parhamn 6y agoWe agree. I think python is great. I actually asked because python usually makes things dead simple and straightforward. > Unfortunately, I don't think that the "wider audience" is those who are looking for concurrency. I don't buy this. Many network heavy shops use Python so concurrency is relevant. The language is used in web, finance, cloud, data pipelining/etl, and so many more. Dropbox, Robinhood, Spotify, Instagram, Uber, Google, etc, are the "wider audience" and they certainly care about concurrency.
- jordic 6y agoSince version 3.7 you don't need to touch the loop for nothing, also some old signatures had deprecated the loop param... It's almost the same as if you work with node, but with a bit more sugar (tasks, gather, wait, wait_for) When you work with asyncio daily it's so natural and fun.
- skrtskrt 6y agoAgreed, Python’s async model is the easiest one for me to think about by far and there’s so many high quality libraries
- t-writescode 6y agoHave you used C#'s or Akka's or Go's? I find 2 of those to be easier to reason about and all to be superior.
- jordic 6y agoyes, goroutines are fast and easy... but this thread is about python. I love both languages, and go is fast and safe, but, I also like python (it's fast developing... )
- rumanator 6y ago> yes, goroutines are fast and easy... but this thread is about python. The OP was commenting on what in his opinion was the easiest. That explicitly represents a judgement of Python's features compared with those offered by other languages. Are we supposed to only praise Python in threads about Python?
- jordic 6y agoThought, you misunderstood my opinion, mostly that sometimes there are project constraints, usual the language.. between the python constrain asyncio it's not bad.
- 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.