Skip to content

Commit

Permalink
Merge branch 'fix-asyncio' into 'master'
Browse files Browse the repository at this point in the history
Quick hacky fix for asyncio

There may be a reason we weren't creating the `_call_task` in `__init__`, but I'm not sure what it was.

See merge request !6
  • Loading branch information
Elizafox committed Jan 7, 2016
2 parents 21e7a1c + 8a94f6c commit f6afb9c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions PyIRC/io/asyncio.py
Expand Up @@ -49,7 +49,10 @@ class IRCProtocol(IRCBase, asyncio.Protocol):

def __init__(self, *args, **kwargs):
self._call_queue = asyncio.Queue()
self._call_task = None

# Start the task queue
self._call_task = asyncio.async(self._process_queue())
self._call_task.add_done_callback(self._process_queue_exit)

super().__init__(*args, **kwargs)

Expand All @@ -70,10 +73,6 @@ def connect(self):
:returns:
An asyncio coroutine representing the connection.
"""
# Start the task queue
self._call_task = asyncio.async(self._process_queue())
self._call_task.add_done_callback(self._process_queue_exit)

loop = asyncio.get_event_loop()
return loop.create_connection(lambda: self, self.server, self.port,
ssl=self.ssl)
Expand Down Expand Up @@ -139,7 +138,6 @@ def _process_queue(self):

def _process_queue_exit(self, future):
_logger.critical("Process queue died!")
self._call_task = None
self._call_queue = asyncio.Queue()
self.close()

Expand All @@ -149,7 +147,7 @@ def call_event(self, hclass, event, *args, **kwargs):
If no args are passed in, and the signal is in a deferred state, the
arguments from the last call_event will be used.
"""
if self._call_task and self._call_task.exception():
if self._call_task.done() and self._call_task.exception():
# Exception raised, let's get out of here!
raise self._call_task.exception()

Expand Down

0 comments on commit f6afb9c

Please sign in to comment.