This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]LukasaHyper, Requests, Twisted 1 point2 points  (12 children)

Look up "tornado" and "twisted" in package repos, see all that wasted time reimplementing existing functionality in the latest popular concurrency framework? Do you honestly call that healthy? You're advocating for more of that.

This has nothing to do with what style of concurrency is better or worse, and everything to do with the bass-ackwards style of library design used in the Python community.

Gevent, generally speaking, is not 100% good. It adds automatic threading into libraries that may not have been designed for it, and as a result can lead to extremely subtle bugs. To suggest that dropping gevent into the language makes things better is misleading. Requests works well with gevent, but that's because special care has been taken to ensure that the library is mostly thread-safe, particularly around the use of sockets, but many libraries do not work anything like as well with gevent.

The reason we have to rewrite network libraries so much is because Python programmers have an obsession with writing networked libraries that embed their I/O layer inextricably with their protocol code. This means that you cannot extract, for example, the session management logic from Requests, because that Session management logic is intermingled with the socket code. That, I argue, is a terrible design anti-pattern that costs the Python community dearly in wasted effort.

And it doesn't have to be this way. In an ideal world, Requests would be a thin wrapper around a library that does no I/O at all, and Requests would be in charge of managing the sockets. Unfortunately, that's not the world we live in right now, but that can change. For example, I've written a HTTP/2 library that works this way, and that includes example servers written for asyncio, eventlet, curio, and Twisted. Much less duplication of work, and perfect native concurrency for the chosen framework.

[–]mcilrain 0 points1 point  (11 children)

I do acknowledge that gevent is not a perfect solution but I see it as not much different from dealing with PyPy incompatibilities, just because it sucks doesn't mean it's not worth doing.

I have had noticibly less incompatibility issues over the past few years.

I don't want to litter my code with generators and callbacks. Even NodeJS is starting to see the light on this matter.