def _detect_environment(): # ## -eventlet- if 'eventlet' in sys.modules: try: import socket from eventlet.patcher import is_monkey_patched as is_eventlet if is_eventlet(socket): return 'eventlet' except ImportError: pass # ## -gevent- if 'gevent' in sys.modules: try: import socket from gevent import socket as _gsocket if socket.socket is _gsocket.socket: return 'gevent' except ImportError: pass return 'default'
def _detect_greenthread_environment() -> str: """ Detect if eventlet or gevent are in use """ if 'eventlet' in sys.modules: try: from eventlet.patcher import is_monkey_patched as is_eventlet import socket if is_eventlet(socket): return 'eventlet' except ImportError: pass if 'gevent' in sys.modules: try: from gevent import socket as _gsocket import socket if socket.socket is _gsocket.socket: return 'gevent' except ImportError: pass return 'default'
def detect_sync_method(): """Detect method to use for blocking calls.""" ## -eventlet- if "eventlet" in sys.modules: try: from eventlet.patcher import is_monkey_patched as is_eventlet import socket if is_eventlet(socket): return _sync_eventlet() except ImportError: pass # -gevent- if "gevent" in sys.modules: try: from gevent import socket as _gsocket import socket if socket.socket is _gsocket.socket: return _sync_gevent() except ImportError: pass return _sync_default()
def detect_environment(): ## -eventlet- if "eventlet" in sys.modules: try: from eventlet.patcher import is_monkey_patched as is_eventlet import socket if is_eventlet(socket): return "eventlet" except ImportError: pass # -gevent- if "gevent" in sys.modules: try: from gevent import socket as _gsocket import socket if socket.socket is _gsocket.socket: return "gevent" except ImportError: pass return "default"
def _detect_environment(): # ## -eventlet- if 'eventlet' in sys.modules: try: from eventlet.patcher import is_monkey_patched as is_eventlet import socket if is_eventlet(socket): return 'eventlet' except ImportError: pass # ## -gevent- if 'gevent' in sys.modules: try: from gevent import socket as _gsocket import socket if socket.socket is _gsocket.socket: return 'gevent' except ImportError: pass return 'default'
self._rfd.add(fd) elif events & POLL_READ: self._rfd.add(fd) def unregister(self, fd): self._rfd.discard(fd) self._efd.discard(fd) def poll(self, timeout): read, _write, error = select.select(self._rfd, [], self._efd, timeout) events = {} for fd in read: fd = fd.fileno() events[fd] = events.get(fd, 0) | POLL_READ for fd in error: fd = fd.fileno() events[fd] = events.get(fd, 0) | POLL_ERR return events.items() if is_eventlet(select): # use Eventlet's non-blocking version of select.select poll = _select elif hasattr(select, "epoll"): # Py2.6+ Linux poll = _epoll elif hasattr(select, "kqueue"): # Py2.6+ on BSD / Darwin poll = _kqueue else: poll = _select
elif events & POLL_READ: self._rfd.add(fd) def unregister(self, fd): self._rfd.discard(fd) self._efd.discard(fd) def poll(self, timeout): read, _write, error = select.select(self._rfd, [], self._efd, timeout) events = {} for fd in read: fd = fd.fileno() events[fd] = events.get(fd, 0) | POLL_READ for fd in error: fd = fd.fileno() events[fd] = events.get(fd, 0) | POLL_ERR return events.items() if is_eventlet(select): # use Eventlet's non-blocking version of select.select poll = _select elif hasattr(select, "epoll"): # Py2.6+ Linux poll = _epoll elif hasattr(select, "kqueue"): # Py2.6+ on BSD / Darwin poll = _kqueue else: poll = _select