Is there a generic notion of asynchronous programming in python? Could I assign a callback to a function, execute it and return to the main program flow immediately, no matt
Good news everyone!
Python 3.4 would include brand new ambitious asynchronous programming implementation!
It is currently called tulip and already has an active following.
As described in PEP 3153: Asynchronous IO support and PEP 3156: Asynchronous IO Support Rebooted:
People who want to write asynchronous code in Python right now have a few options:
- asyncore and asynchat;
- something bespoke, most likely based on the select module;
- using a third party library, such as Twisted or gevent.
Unfortunately, each of these options has its downsides, which this PEP tries to address.
Despite having been part of the Python standard library for a long time, the asyncore module suffers from fundamental flaws following from an inflexible API that does not stand up to the expectations of a modern asynchronous networking module.
Moreover, its approach is too simplistic to provide developers with all the tools they need in order to fully exploit the potential of asynchronous networking.
The most popular solution right now used in production involves the use of third party libraries. These often provide satisfactory solutions, but there is a lack of compatibility between these libraries, which tends to make codebases very tightly coupled to the library they use.
This current lack of portability between different asynchronous IO libraries causes a lot of duplicated effort for third party library developers. A sufficiently powerful abstraction could mean that asynchronous code gets written once, but used everywhere.
Here is the brief overview of it's abilities.