Post on 03-Feb-2022
Twisted PostgreSQL
Jan Urbanskij.urbanski@wulczer.org
University of Warsaw / Flumotion
May 20, 2010
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 1 / 9
Who’s interested
Who uses:
PostgreSQL
Python
Psycopg2
Twisted
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 2 / 9
Who’s interested
Who uses:
PostgreSQL
Python
Psycopg2
Twisted
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 2 / 9
Who’s interested
Who uses:
PostgreSQL
Python
Psycopg2
Twisted
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 2 / 9
Who’s interested
Who uses:
PostgreSQL
Python
Psycopg2
Twisted
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 2 / 9
Psycopg2
psycopg2 version 2.2.0 wraps asynchronous libpqAPI
the connection object exposes the file descriptor
the poll() method wraps asynchronouscommunication
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 3 / 9
Psycopg2
psycopg2 version 2.2.0 wraps asynchronous libpqAPI
the connection object exposes the file descriptor
the poll() method wraps asynchronouscommunication
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 3 / 9
Psycopg2
psycopg2 version 2.2.0 wraps asynchronous libpqAPI
the connection object exposes the file descriptor
the poll() method wraps asynchronouscommunication
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 3 / 9
Psycopg2 example
Going async
c u r = conn . c u r s o r ( )c u r . e x e c u t e ( ’ s e l e c t c o l from b i g ’ )w h i l e True :
s t a t e = conn . p o l l ( )i f s t a t e == POLL OK :
b r e a ke l i f s t a t e == POLL READ :
s e l e c t . s e l e c t ( [ conn . f i l e n o ( ) ] , [ ] , [ ] )e l i f s t a t e == POLL WRITE :
s e l e c t . s e l e c t ( [ ] , [ conn . f i l e n o ( ) ] , [ ] )p r i n t c u r . f e t c h a l l ( )
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 4 / 9
Twisted
event-driven network engine
has an asynchronous, single-threaded main loop
used to do threads for database access
no more threads using the new bindings (sweet!)
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 5 / 9
Twisted
event-driven network engine
has an asynchronous, single-threaded main loop
used to do threads for database access
no more threads using the new bindings (sweet!)
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 5 / 9
Twisted
event-driven network engine
has an asynchronous, single-threaded main loop
used to do threads for database access
no more threads using the new bindings (sweet!)
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 5 / 9
Twisted
event-driven network engine
has an asynchronous, single-threaded main loop
used to do threads for database access
no more threads using the new bindings (sweet!)
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 5 / 9
Other nice things
green threads
coroutines
seamless SQLAlchemy/Django integration
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 6 / 9
Other nice things
green threads
coroutines
seamless SQLAlchemy/Django integration
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 6 / 9
Other nice things
green threads
coroutines
seamless SQLAlchemy/Django integration
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 6 / 9
Linkies
http://initd.org/psycopg2/ - home of thepsycopg2 driver
http://twistedmatrix.com/ - home of Twisted
http://launchpad.net/txpostgres - drop-inreplacement for Twisted database API
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 7 / 9
Folks
Federico Di Gregorio
Daniele Varrazzo
yours truly
Jan Urbanski j.urbanski@wulczer.org (University of Warsaw / Flumotion)Twisted PostgreSQL May 20, 2010 8 / 9