Added a fix for running with postgresql-psycopg2. This does not actually resolve the problem as much as circumvent it, so I'm not marking Issue 115 as closed just yet.

This commit is contained in:
Griatch 2012-06-16 14:51:22 +02:00
parent f15e26c54a
commit 9e2ad59663
5 changed files with 48 additions and 24 deletions

View file

@ -449,7 +449,7 @@ def format_table(table, extra_space=1):
for icol, col in enumerate(table)])
return ftable
def run_async(async_func, at_return=None, at_err=None):
def run_async(async_func, *args, **kwargs):
"""
This wrapper will use Twisted's asynchronous features to run a slow
function using a separate reactor thread. In effect this means that
@ -467,20 +467,25 @@ def run_async(async_func, at_return=None, at_err=None):
your async_func under sqlite3 you will probably run very slow or even get
tracebacks.
async_func() - function that should be run asynchroneously
at_return(r) - if given, this function will be called when async_func returns
value r at the end of a successful execution
at_err(e) - if given, this function is called if async_func fails with an exception e.
use e.trap(ExceptionType1, ExceptionType2)
arg:
async_func - function that should be run asynchroneously
reserved keywords:
at_return(r) - if given, this function will be called when async_func returns
value r at the end of a successful execution
at_err(e) - if given, this function is called if async_func fails with an exception e.
use e.trap(ExceptionType1, ExceptionType2)
all other arguments/keywords will be used as args/kwargs fro async_func.
"""
# create deferred object
deferred = threads.deferToThread(async_func)
if at_return:
deferred.addCallback(at_return)
if at_err:
deferred.addErrback(at_err)
deferred = threads.deferToThread(async_func, *args, **kwargs)
if "at_return" in kwargs:
deferred.addCallback(kwargs["at_return"])
if "at_err" in kwargs:
deferred.addErrback(kwargs["at_err"])
# always add a logging errback as a last catch
def default_errback(e):
from src.utils import logger