Die Threads: Python async code [video]
youtube.com
youtube.com
Edit: Here is a recording of the talk where you can both see the slides and the speaker: https://www.youtube.com/watch?v=xOyJiN3yGfU
Sad to see that it has not received any love for last 4 months, is there another "preferred" thread lib for Python?
I also use gevent a lot. I'm currently in love with cooperative multitasking.
Why is this a bad thing? Unless thredo is littered with bugs, who cares how old it is?
In other words, if I build a codebase to rely on something other than the stdlib it's nice to know that it'll have at least some support down the line.
No no, it now supports Python 3 wonderfully. It took a very long time, because a lot of what Twisted does was more dramatically changed from 2-3 than a lot of projects. Consider, for example, the implications of PEP-3333, which required that headers be in the native str type in Python 2, but also the native str type (ie, unicode) in Python 3. This was a tough problem. [0]
However, those days are long behind us. Not only does Twisted support Python 3, but it can interchange its own flow control (ie, the reactor) with the asyncio event loop, and also convert (and ensure) that Futures and Deferreds fire in a way that is cross-compatible. You can also use the inlineCallback decorator to see all of the new coroutine syntactic sugar.
Here's a project I'm working on right now that is Python 3.6+ with Twisted: https://github.com/nucypher/nucypher/
> I've also always found the code it produces difficult to test.
Yeah, I hear that a lot, and for my part, I've just never had that trouble, so I'm not sure how to respond. Have you ever read the "TDD with Twisted" document[1]? Also, the new pytest-twisted tooling helps quite a bit if you're using pytest.
0: https://github.com/twisted/twisted/blob/6ac66416c0238f403a8d... 1: https://twistedmatrix.com/documents/current/core/howto/trial...
@inlineCallbacks
def get_index_status(self, index_id):
uri = "{}/index-status?id={}".format(self.SERVER, index_id) #yes, no escaping, as this is silly test only
r = yield self.get(uri)
returnValue(r.text)
Using raw Deferreds is a big more difficult.Kudos to Twisted team!
Amber Brown took over as release manager, python 3 compatibility landed, lots of new test utilities, Glyph and some of the original authors took steps back but are still involved, IHandshakeListener (makes TLS easier), support for TLS 1.3 cypher suites (though full support is still pending PyOpenSSL I guess?), WSGIResource supports IPv6...
I maintain a Twisted-based web server called hendrix; we have integrated many of the new coolness and are fully Python 3 compatible. Check it out: https://github.com/hendrix/hendrix
Implementation-wise, this could be made simpler than removing the GIL, if we just fully give up on the concept of shared memory. (This is above my pay-grade, anyone with CPython internals knowledge, please share your thoughts!)
I've been trying to build a shared state system over message passing that doesn't use shared memory at all [2], and I have experienced that OS level processes are a high cost to pay, when you try to do things the Erlang way, launching thousands of processes.
[1] https://hamidreza-s.github.io/erlang/scheduling/real-time/pr...
I can already do multi server just fine, but not everything is in the server domain. Also I don't seek multi-core usage for performance, specifically. Versatility is what I'm going for here.
An Erlang like system can be both performant and scalable to thousands of clients.
The current scope of python really only allows for either one. You can go either multiprocessing, which will give great processing power, but you can only launch so many of them. You can go asyncio route and launch millions of coroutines, but they suffer from performance issues.