4 ms·
Here's the said black magic (for amd64/unix) that the gevent project relies on: https://github.com/python-greenlet/greenlet/blob/master/src/greenlet/platform/s
by plq 3y ago
Here's the said black magic (for amd64/unix) that the gevent project relies on:
https://github.com/python-greenlet/greenlet/blob/master/src/greenlet/platform/switch_amd64_unix.h https://github.com/python-greenlet/greenlet/blob/master/src/...
I still think it's too much for a Python project -- if you think you need this in 2023, maybe you need to reevaluate? I'd seriously have another look at Go.
- Blackthorn 3y agoThat's surprisingly readable and understandable. Nice work by the authors for encapsulating it so well.
- d1l 3y agoAll greenlet does is allow the Python frames to managed separately from the C call stack - it is very similar to what Pypy is also doing. I don't think your characterization is at all accurate.
- plq 3y agoSorry I wasn't clear -- my point was that a typical python programmer won't be able to troubleshoot these bits -- it'd be way outside their skill set. Before anyone jumps in to say nobody ever has/will ever have to troubleshoot this because it's so stable and used everywhere and so forth, please have a look at the comments at the top of that file. This code had to be patched eg. due to a compiler update. Remember, this is open source and this code is offered without any guarantees. And non-existing guarantees of greenlet/gevent is quite different from the non-existing guarantees of CPython (no idea about PyPy). Implementing cooperative multitasking at this level is way off the beaten path and should only be attempted by those who know what they are doing. Today, I'm sure this code works perfectly on linux 6.4.7 when compiled by gcc 12.3.1 against python 3.10 on amd64 architecture in release mode. But can you guarantee it will it work on linux 7.8.17 when compiled by gcc 15.2 against python 3.21 on AARCH64 10.4 architecture? No you can't. If you are lucky, it'll just die with a general protection fault or something. But it can also break in subtle ways that only a seasoned systems programmer can realize, let alone fix. So if you are a professional, you care about maintainability, you care about forward compatibility, you are starting a greenfield project, you are sure you need cooperative multitasking and you ask nicely my opinion about which async framework you should choose, I would strongly advise you to steer clear of gevent/greenlet based libraries. Or, you know, just hack away :)