mfenniak / pg8000

A Pure-Python PostgreSQL Driver
http://pythonhosted.org/pg8000/
Other
222 stars 55 forks source link

asyncio fork #82

Closed realazthat closed 8 years ago

realazthat commented 9 years ago

Hi, I made a fork called aiopg8000 for use with asyncio (python 3.4+). This allows asynchronous I/O, which allows you to handle many simultaneous connections without blocking, and without using system threads. Instead, asyncio manages lightweight threads, which yield to eachother while waiting for I/O.

Asynchronous code can be written with callbacks (like nodejs, and tornado webserver used to), but asyncio allows the code to be written without callbacks using the yield from notation and marking methods with a @coroutine decorator. The cons are that almost every function in the callstack must be marked as a coroutine to be useful, and the yield from notation is only available in python 3.3+, and asyncio itself is only available in 3.4+. Options, prior to 3.4 include the trollius library, an implementation of asyncio that uses yield From( ... ) syntax to make it compatible for 2.x and 3.x. Unfortunately it is difficult to write code compatible for both trollius and asyncio. I opted for asyncio, but with some fancy find/replace one can easily make aiopg8000-trollius. If I find an easy way to be compatible with both, I will add trollius support (and thus support 2.x, and python<3.4).

Alternative postgres asyncio projects include aiopg, had a few issues that bugged me, so I found a pure-python implementation I could convert, and yay! pg8000.

mfenniak commented 9 years ago

That's really cool, @realazthat. I'm glad that pg8000 made a good base for that project.

pylover commented 8 years ago

+1, thanks a lot