Commits

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)

gevent/__init__.py

 from gevent.timeout import Timeout, with_timeout
 from gevent.hub import getcurrent, GreenletExit, spawn_raw, sleep, idle, kill, signal, reinit
 try:
-    from gevent.hub import fork
+    from gevent.os import fork
 except ImportError:
     __all__.remove('fork')
 

gevent/fileobject.py

 import os
 from gevent.hub import get_hub
 from gevent.socket import EBADF
+from gevent.os import os_read, os_write
 
 
 try:
             bytes_written = 0
             while bytes_written < bytes_total:
                 try:
-                    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:
                 try:
-                    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:
            'kill',
            'signal',
            'reinit',
-           'fork',
            'get_hub',
            'Hub',
            'Waiter']
 threadlocal = thread._local
 _threadlocal = threadlocal()
 _threadlocal.Hub = None
-try:
-    _original_fork = os.fork
-except AttributeError:
-    _original_fork = None
-    __all__.remove('fork')
 get_ident = thread.get_ident
 MAIN_THREAD = get_ident()
 
         hub.loop.reinit()
 
 
-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():

greentest/test__all__.py

            'gevent.select': 'select',
            'gevent.ssl': 'ssl',
            'gevent.thread': 'thread',
-           'gevent.subprocess': 'subprocess'}
+           'gevent.subprocess': 'subprocess',
+           'gevent.os': 'os'}
 
 
 class ANY(object):
 NOT_IMPLEMENTED = {
     'socket': ['CAPI'],
     'thread': ['allocate', 'exit_thread', 'interrupt_main', 'start_new'],
-    'select': ANY}
+    'select': ANY,
+    'os': ANY}
 
 COULD_BE_MISSING = {
     '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 ProjectModifiedEvent.java.
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.