Prev | Index | Next

Thread example code

from twisted.internet import threads
from pyPgSQL import PgSQL

def _doSelect(key):
    c = PgSQL.connect(database='test')
    cursor = c.cursor()
    s = 'SELECT * FROM names WHERE key = %s'
    cursor.execute(s, key)
    return cursor.fetchall()

def select(key):
    return threads.deferToThread(
        _doSelect, key)