Kavya Joshi - A tale of concurrency through creativity in Python: a deep dive into how gevent works.
Вставка
- Опубліковано 20 сер 2024
- Speaker: Kavya Joshi
gevent is an open source Python library for asynchronous I/O. It provides a powerful construct to build concurrent applications; think threads, except lightweight and cooperatively scheduled. We will delve into how gevent is architected from its building blocks - sophisticated coroutines, an event loop, and a dash of creativity to neatly integrate them.
Slides can be found at: speakerdeck.co... and github.com/PyC...
Perfect. This gave me exactly the information I needed to decide how to proceed on what I want to do. I’m not sure why we need stack slicing to implement green threads when we have the yield keyword. It’s technically for generator functions, but those are just a special case of coroutine. It’s a perfectly viable option for implementing greenlets, as far as I can tell.
Very good structured presentation and a good explanation of under the hood mechanics.
Excellent presentation. Very clear and technically deep.
very neat deep dive
I am using it for my work.
Great presentation
Kavya: They wrote assembly code that removes and restores the stack from under the CPython interpreter's nose, isn't that cool!
Me: Not so cool when you have to debug that lmfao.
Awesome talk tho :D
GIL does not block threads when IO.
She never said that
it's too hard for me to understand..
so, if greenlet_1 will overwrite greenlet_2's stack when it runs again, next time greenlet_2 wants to run, its saved stack needs to be copied back to the stack from the heap, right? It looks like to me that the first greenlet to run will be a priviliged greenlet in a sense, that it doesn't need copying or whatsoever, hence it will run a bit faster than the others. Also what's the point in saving the base stack pointer for greenlet_2 if that area can easily be overwritten by greenlet_1?
Does Cpython provide an API to access(maybe a read-only access) to the C-Stacks and heap?
asyncio is not based on callbacks (in user space).
It is fully based on callbacks. There's nothing else that the event loop interacts with. Coroutines are wrapped in Task instances which schedule _step callbacks (a trampoline pattern).
Is there anything similar in Java, that can make a network call without blocking the thread?
Learning Kotlin coroutine recently and I looking at this video again. I got another question - Coroutines should not block its thread. Can two greenlets send out two IO operations concurrently without blocking each other?
Answer my own question: the socket is nonblocking. we just need one thread for event loop. A greenlet being ready is registered as an event. An HTTP request registers READABLE event with a callback. The callback is the greenlet.switch() which makes a greenlet ready to run. Other ready greenlets run in the eventloop while waiting for that HTTP response. Coroutines are all in the same thread as the event loop.
小姐姐太可爱了
lecturer should have better understanding of python threading, no solution was presented