def __init__(self): super(MsgGenerator, self).__init__() self._complete = Event() self._jobs = {} self._instances = [] # FIXME: monkey patch the whole world # because the python side of librados # uses threading.Thread. However, rados # itself will still do blocking on e.g. # connect(), so we probably need to wrap # librados in its own non-gevent python # process and RPC to it. from gevent import monkey monkey.patch_all() monkey.patch_subprocess()
def test_patch_subprocess_twice(self): self.assertNotIn('gevent', repr(Popen)) self.assertIs(Popen, monkey.get_original('subprocess', 'Popen')) monkey.patch_subprocess() self.assertIs(Popen, monkey.get_original('subprocess', 'Popen'))
#!/usr/bin/env python import os import sys from gevent import monkey#; monkey.patch_all() monkey.patch_os() monkey.patch_time() monkey.patch_thread( _threading_local=False) monkey.patch_sys() monkey.patch_socket() monkey.patch_select() monkey.patch_ssl() monkey.patch_subprocess() from psycogreen.gevent import patch_psycopg; patch_psycopg(); if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "geventpooltest.settings") from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)
# Monkey-patching modules individually can be about 20% faster, # or, in absolute terms, instead of 275 ms it may take 220 ms. from gevent.monkey import patch_builtins, patch_contextvars, patch_thread, patch_time, patch_os, patch_queue, patch_select, \ patch_selectors, patch_signal, patch_socket, patch_ssl, patch_subprocess, patch_sys # Note that the order of patching matters, just like in patch_all patch_os() patch_time() patch_thread() patch_sys() patch_socket() patch_select() patch_selectors() patch_ssl() patch_subprocess() patch_builtins() patch_signal() patch_queue() patch_contextvars() # stdlib import locale import logging import os import ssl import sys from logging.config import dictConfig # ConcurrentLogHandler - updates stlidb's logging config on import so this needs to stay import cloghandler
#!/usr/bin/env python from __future__ import (absolute_import, division, print_function, unicode_literals) from pyaib.ircbot import IrcBot from gevent.monkey import patch_subprocess patch_subprocess() import sys import os argv = sys.argv[1:] bot = IrcBot(argv[0] if argv else 'botbot.conf') print("Config Dump: %s" % bot.config) bot.run()
- `Queue` - `JoinableQueue` - `Empty` - `Thread` (`gevent.Greenlet`) - `joinall` - `sleep` """ import os import sys # namespace imports if os.name == 'posix' and sys.version_info < (3, 5, 0): import subprocess32 as subprocess else: import subprocess # FIXME #from gevent import subprocess from gevent.queue import Queue, JoinableQueue, Empty # noqa from gevent import Greenlet as Thread # noqa from gevent import joinall, sleep, monkey # noqa monkey.patch_thread() monkey.patch_subprocess() monkey.patch_select() # FIXME: patching time breaks startup, figure # out why as it makes sense for it to be patched # monkey.patch_time()