Commit 472cdf2a authored by Geert Jansen's avatar Geert Jansen

Add "gevent.os" module.

This initial implementation contains cooperative read() and write(),
and also moves fork() from gevent.hub to gevent.os.
parent 8bddde23
......@@ -45,7 +45,7 @@ spawn_later = Greenlet.spawn_later
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')
......
......@@ -3,6 +3,7 @@ import sys
import os
from gevent.hub import get_hub
from gevent.socket import EBADF
from gevent.os import os_read, os_write
try:
......@@ -98,7 +99,7 @@ else:
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:
......@@ -112,7 +113,7 @@ else:
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:
......
......@@ -20,7 +20,6 @@ __all__ = ['getcurrent',
'kill',
'signal',
'reinit',
'fork',
'get_hub',
'Hub',
'Waiter']
......@@ -70,11 +69,6 @@ else:
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()
......@@ -184,15 +178,6 @@ def reinit():
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.
......
......@@ -125,12 +125,7 @@ def patch_module(name, items=None):
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():
......
......@@ -10,7 +10,8 @@ MAPPING = {'gevent.local': '_threading_local',
'gevent.select': 'select',
'gevent.ssl': 'ssl',
'gevent.thread': 'thread',
'gevent.subprocess': 'subprocess'}
'gevent.subprocess': 'subprocess',
'gevent.os': 'os'}
class ANY(object):
......@@ -22,7 +23,8 @@ ANY = ANY()
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']}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment