1. Geert Jansen
  2. gevent


Geert Jansen  committed 2ccffd0

Add "gevent.os" module.

This initial implementation contains cooperative read() and write(),
and also moves fork() from gevent.hub to gevent.os.

  • Participants
  • Parent commits 9def266
  • Branches default

Comments (0)

Files changed (5)

File gevent/__init__.py

View file
 from gevent.timeout import Timeout, with_timeout
 from gevent.hub import getcurrent, GreenletExit, spawn_raw, sleep, idle, kill, signal, reinit
-    from gevent.hub import fork
+    from gevent.os import fork
 except ImportError:

File gevent/fileobject.py

View file
 import os
 from gevent.hub import get_hub
 from gevent.socket import EBADF
+from gevent.os import os_read, os_write
             bytes_written = 0
             while bytes_written < bytes_total:
-                    bytes_written += os.write(fileno, _get_memory(data, bytes_written))
+                    bytes_written += os_write(fileno, _get_memory(data, bytes_written))
                 except (IOError, OSError):
                     code = sys.exc_info()[1].args[0]
                     if code == EINTR:
         def recv(self, size):
             while True:
-                    data = os.read(self.fileno(), size)
+                    data = os_read(self.fileno(), size)
                 except (IOError, OSError):
                     code = sys.exc_info()[1].args[0]
                     if code == EBADF:

File gevent/hub.py

View file
-           'fork',
 threadlocal = thread._local
 _threadlocal = threadlocal()
 _threadlocal.Hub = None
-    _original_fork = os.fork
-except AttributeError:
-    _original_fork = None
-    __all__.remove('fork')
 get_ident = thread.get_ident
 MAIN_THREAD = get_ident()
-if _original_fork is not None:
-    def fork():
-        result = _original_fork()
-        if not result:
-            reinit()
-        return result
 def get_hub_class():
     """Return the type of hub to use for the current thread.

File gevent/monkey.py

View file
 def patch_os():
     """Replace :func:`os.fork` with :func:`gevent.fork`. Does nothing if fork is not available."""
-    try:
-        from gevent.hub import fork
-    except ImportError:
-        return
-    import os
-    patch_item(os, 'fork', fork)
+    patch_module('os')
 def patch_time():

File greentest/test__all__.py

View file
            'gevent.select': 'select',
            'gevent.ssl': 'ssl',
            'gevent.thread': 'thread',
-           'gevent.subprocess': 'subprocess'}
+           'gevent.subprocess': 'subprocess',
+           'gevent.os': 'os'}
 class ANY(object):
     'socket': ['CAPI'],
     'thread': ['allocate', 'exit_thread', 'interrupt_main', 'start_new'],
-    'select': ANY}
+    'select': ANY,
+    'os': ANY}
     'socket': ['create_connection', 'RAND_add', 'RAND_egd', 'RAND_status']}