Skip to content

Do a last polling before closing the IocpProactor #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Implementation of the `PEP 3156`_ Event-Loop with Qt

Requirements
============
Quamash requires Python 3.4 or Python 3.3 with the backported ``asycnio`` library and either PyQt4, PyQt5 or PySide.
Quamash requires Python 3.4 or Python 3.3 with the backported ``asyncio`` library and either PyQt4, PyQt5 or PySide.

Installation
============
Expand Down
1 change: 1 addition & 0 deletions quamash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ def call_exception_handler(self, context):
return

try:
self._logger.debug('Calling client exception handler')
self.__exception_handler(self, context)
except Exception as exc:
# Exception in the user set custom exception handler.
Expand Down
16 changes: 13 additions & 3 deletions quamash/_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _process_events(self, events):
self._logger.debug('Invoking event callback {}'.format(callback))
value = callback(transferred, key, ov)
except OSError as e:
self._logger.warn('Event callback failed: {}'.format(e))
self._logger.warning('Event callback failed: {}'.format(e))
f.set_exception(e)
else:
f.set_result(value)
Expand Down Expand Up @@ -70,15 +70,19 @@ def select(self, timeout=None):

def close(self):
self._logger.debug('Closing')
self._poll(0.2)
super(_IocpProactor, self).close()

def _poll(self, timeout=None):
"""Override in order to handle events in a threadsafe manner."""
if timeout is None:
ms = UINT32_MAX # wait for eternity
elif timeout < 0:
raise ValueError("negative timeout")
else:
if not isinstance(timeout, (int, float)):
raise TypeError('timeout must be a number')
if timeout < 0:
raise ValueError("negative timeout")

# GetQueuedCompletionStatus() has a resolution of 1 millisecond,
# round away from zero to wait *at least* timeout seconds.
ms = math.ceil(timeout * 1e3)
Expand All @@ -88,8 +92,14 @@ def _poll(self, timeout=None):
while True:
# self._logger.debug('Polling IOCP with timeout {} ms in thread {}...'.format(
# ms, threading.get_ident()))
if self._iocp is None:
self._logger.debug('Stopping polling since IOCP handle is disposed')
break

assert 0 <= ms <= UINT32_MAX
status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms)
if status is None:
self._logger.debug('Stopping polling since None was returned for status')
break

err, transferred, key, address = status
Expand Down