diff --git a/mockssh/server.py b/mockssh/server.py index 2b69ffe..16d04aa 100644 --- a/mockssh/server.py +++ b/mockssh/server.py @@ -1,7 +1,6 @@ import errno import logging import os -import select import socket import subprocess import threading @@ -11,6 +10,12 @@ except ImportError: # Python 2.7 from Queue import Queue +try: + import selectors +except ImportError: # Python 2.7 + import selectors2 as selectors + + import paramiko from mockssh import sftp @@ -129,10 +134,12 @@ def __enter__(self): def _run(self): sock = self._socket + selector = selectors.DefaultSelector() + selector.register(sock, selectors.EVENT_READ) while sock.fileno() > 0: self.log.debug("Waiting for incoming connections ...") - rlist, _, _ = select.select([sock], [], [], 1.0) - if rlist: + events = selector.select(timeout=1.0) + if events: try: conn, addr = sock.accept() except OSError as ex: diff --git a/requirements.txt b/requirements.txt index 8608c1b..487233b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ paramiko +selectors2; python_version < '3.4' \ No newline at end of file