Skip to content

Commit

Permalink
Merge pull request #56 from Snawoot/fix_asdnotify
Browse files Browse the repository at this point in the history
asdnotify: fix high CPU usage
  • Loading branch information
Snawoot authored Jan 26, 2020
2 parents 6ef4606 + 88999db commit 49b9547
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions postfix_mta_sts_resolver/asdnotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self):
self._started = False
self._loop = None
self._queue = asyncio.Queue(MAX_QLEN)
self._monitor = False

@property
def started(self):
Expand All @@ -28,8 +29,11 @@ def _drain(self):
msg = self._queue.get_nowait()
self._queue.task_done()
self._send(msg)
if self._monitor:
self._loop.remove_writer(self._sock.fileno())
except BlockingIOError: # pragma: no cover
pass
self._monitor = True
self._loop.add_writer(self._sock.fileno(), self._drain)
except OSError:
pass

Expand All @@ -43,7 +47,6 @@ async def start(self):
try:
self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
self._sock.setblocking(0)
self._loop.add_writer(self._sock.fileno(), self._drain)
self._started = True
except OSError:
return False
Expand Down

0 comments on commit 49b9547

Please sign in to comment.