Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Commit

Permalink
Added checks for callbacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
FSX committed Dec 19, 2012
1 parent d7f83fe commit 4f1f404
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 8 additions & 3 deletions momoko/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ def __init__(self,
self._transaction_status = self.connection.get_transaction_status
self.ioloop = ioloop or IOLoop.instance()

self.callback = partial(callback, self)
if callback:
self.callback = partial(callback, self)

self.ioloop.add_handler(self.fileno, self.io_callback, IOLoop.WRITE)

def io_callback(self, fd=None, events=None):
Expand All @@ -197,11 +199,14 @@ def io_callback(self, fd=None, events=None):
if not isinstance(error, psycopg2.DatabaseError):
self.ioloop.update_handler(self.fileno, 0)

self.callback(error)
if self.callback:
self.callback(error)
else:
if state == POLL_OK:
self.ioloop.update_handler(self.fileno, 0)
self.callback(None)

if self.callback:
self.callback(None)
elif state == POLL_READ:
self.ioloop.update_handler(self.fileno, IOLoop.READ)
elif state == POLL_WRITE:
Expand Down
1 change: 0 additions & 1 deletion momoko/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
MIT, see LICENSE for more details.
"""


import sys
from tornado import gen
from functools import partial
Expand Down

0 comments on commit 4f1f404

Please sign in to comment.