[Pkg-bitcoin-commits] [python-quamash] 26/269: Attempt for non-Windows support

Jonas Smedegaard dr at jones.dk
Fri Nov 24 11:26:12 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository python-quamash.

commit 3bc32a23c230d098c62722d47c03a6851923499c
Author: Arve Knudsen <arve.knudsen at gmail.com>
Date:   Tue Jul 1 16:05:04 2014 +0200

    Attempt for non-Windows support
---
 quamash/__init__.py | 125 ++++++++++++++++++++++++++--------------------------
 1 file changed, 62 insertions(+), 63 deletions(-)

diff --git a/quamash/__init__.py b/quamash/__init__.py
index d0b4a02..b324966 100644
--- a/quamash/__init__.py
+++ b/quamash/__init__.py
@@ -13,7 +13,6 @@ __license__ = 'BSD 2 Clause License'
 import sys
 import os
 import asyncio
-from asyncio import windows_events
 import time
 from functools import wraps
 import logging
@@ -42,67 +41,6 @@ def _with_logger(cls):
 
 
 @_with_logger
-class _IocpProactor(windows_events.IocpProactor):
-    def __init__(self):
-        self.__events = []
-        super(_IocpProactor, self).__init__()
-
-    def select(self, timeout=None):
-        """Override in order to handle events in a threadsafe manner."""
-        if not self.__events:
-            self._poll(timeout)
-        tmp = self.__events
-        self.__events = []
-        return tmp
-
-    def close(self):
-        self._logger.debug('Closing')
-        super(_IocpProactor, self).close()
-
-    def _poll(self, timeout=None):
-        """Override in order to handle events in a threadsafe manner."""
-        import math
-        from asyncio import _overlapped
-        INFINITE = 0xffffffff
-
-        if timeout is None:
-            ms = INFINITE
-        elif timeout < 0:
-            raise ValueError("negative timeout")
-        else:
-            # GetQueuedCompletionStatus() has a resolution of 1 millisecond,
-            # round away from zero to wait *at least* timeout seconds.
-            ms = math.ceil(timeout * 1e3)
-            if ms >= INFINITE:
-                raise ValueError("timeout too big")
-
-        while True:
-            self._logger.debug('Polling IOCP with timeout {} ms in thread {}...'.format(
-                ms, threading.get_ident()))
-            status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms)
-
-            if status is None:
-                break
-            err, transferred, key, address = status
-            try:
-                f, ov, obj, callback = self._cache.pop(address)
-            except KeyError:
-                # key is either zero, or it is used to return a pipe
-                # handle which should be closed to avoid a leak.
-                if key not in (0, _overlapped.INVALID_HANDLE_VALUE):
-                    _winapi.CloseHandle(key)
-                ms = 0
-                continue
-
-            if obj in self._stopped_serving:
-                f.cancel()
-            elif not f.cancelled():
-                self.__events.append((f, callback, transferred, key, ov))
-
-            ms = 0
-
-
- at _with_logger
 class _EventPoller(QtCore.QObject):
     """Polling of events in separate thread."""
     sig_events = QtCore.Signal(list)
@@ -249,8 +187,69 @@ def _easycallback(fn):
 
 
 if os.name == 'nt':
-    _baseclass = asyncio.ProactorEventLoop
     import _winapi
+    from asyncio import windows_events
+    _baseclass = asyncio.ProactorEventLoop
+
+    @_with_logger
+    class _IocpProactor(windows_events.IocpProactor):
+        def __init__(self):
+            self.__events = []
+            super(_IocpProactor, self).__init__()
+
+        def select(self, timeout=None):
+            """Override in order to handle events in a threadsafe manner."""
+            if not self.__events:
+                self._poll(timeout)
+            tmp = self.__events
+            self.__events = []
+            return tmp
+
+        def close(self):
+            self._logger.debug('Closing')
+            super(_IocpProactor, self).close()
+
+        def _poll(self, timeout=None):
+            """Override in order to handle events in a threadsafe manner."""
+            import math
+            from asyncio import _overlapped
+            INFINITE = 0xffffffff
+
+            if timeout is None:
+                ms = INFINITE
+            elif timeout < 0:
+                raise ValueError("negative timeout")
+            else:
+                # GetQueuedCompletionStatus() has a resolution of 1 millisecond,
+                # round away from zero to wait *at least* timeout seconds.
+                ms = math.ceil(timeout * 1e3)
+                if ms >= INFINITE:
+                    raise ValueError("timeout too big")
+
+            while True:
+                self._logger.debug('Polling IOCP with timeout {} ms in thread {}...'.format(
+                    ms, threading.get_ident()))
+                status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms)
+
+                if status is None:
+                    break
+                err, transferred, key, address = status
+                try:
+                    f, ov, obj, callback = self._cache.pop(address)
+                except KeyError:
+                    # key is either zero, or it is used to return a pipe
+                    # handle which should be closed to avoid a leak.
+                    if key not in (0, _overlapped.INVALID_HANDLE_VALUE):
+                        _winapi.CloseHandle(key)
+                    ms = 0
+                    continue
+
+                if obj in self._stopped_serving:
+                    f.cancel()
+                elif not f.cancelled():
+                    self.__events.append((f, callback, transferred, key, ov))
+
+                ms = 0
 else:
     _baseclass = asyncio.SelectorEventLoop
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/python-quamash.git



More information about the Pkg-bitcoin-commits mailing list