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.

Comments (0)

Files changed (5)


 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:


 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 =, size)
+                    data = os_read(self.fileno(), size)
                 except (IOError, OSError):
                     code = sys.exc_info()[1].args[0]
                     if code == EBADF:
-           '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.
 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():


            '': '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']}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.