Exemplo n.º 1
0
Arquivo: hub.py Projeto: inercia/evy
    def alarm_itimer (seconds):
        signal.setitimer(signal.ITIMER_REAL, seconds)

    arm_alarm = alarm_itimer
else:
    try:
        import itimer

        arm_alarm = itimer.alarm
    except ImportError:
        def alarm_signal (seconds):
            signal.alarm(math.ceil(seconds))

        arm_alarm = alarm_signal

time = patcher.original('time')





READ = pyuv.UV_READABLE
WRITE = pyuv.UV_WRITABLE



def alarm_handler (signum, frame):
    import inspect
    raise RuntimeError("Blocking detector ALARMED at" + str(inspect.getframeinfo(frame)))

def _signal_checker(handle, signum):
Exemplo n.º 2
0
profile_orig = __import__('profile')
__all__ = profile_orig.__all__

from evy.patcher import slurp_properties

slurp_properties(profile_orig, globals(), srckeys=dir(profile_orig))

import new
import sys
import traceback
import functools

from evy.green import threads as greenthread
from evy import patcher

thread = patcher.original('thread')  # non-monkeypatched module needed


#This class provides the start() and stop() functions
class Profile(profile_orig.Profile):
    base = profile_orig.Profile

    def __init__(self, timer=None, bias=None):
        self.current_tasklet = greenthread.getcurrent()
        self.thread_id = thread.get_ident()
        self.base.__init__(self, timer, bias)
        self.sleeping = {}

    def __call__(self, *args):
        "make callable, allowing an instance to be the profiler"
        r = self.dispatcher(*args)
Exemplo n.º 3
0
#


__import__('pkg_resources').declare_namespace(__name__)



from evy.support import greenlets as greenlet
from evy import patcher

__all__ = ["use_hub",
           "get_hub",
           "get_default_hub",
           "trampoline"]

threading = patcher.original('threading')
_threadlocal = threading.local()




def get_default_hub ():
    """
    Select the default hub implementation based on what multiplexing
    libraries are installed.  The order that the hubs are tried is:
    
    * uv

    .. include:: ../../doc/common.txt
    .. note :: |internal|
    """
Exemplo n.º 4
0
__patched__ = [
    "_start_new_thread",
    "_allocate_lock",
    "_get_ident",
    "_sleep",
    "local",
    "stack_size",
    "Lock",
    "currentThread",
    "current_thread",
    "_after_fork",
    "_shutdown",
]

__orig_threading = patcher.original("threading")
__threadlocal = __orig_threading.local()

patcher.inject("threading", globals(), ("thread", thread), ("time", time))

del patcher

_count = 1


class _GreenThread(object):
    """Wrapper for GreenThread objects to provide Thread-like attributes
    and methods"""

    def __init__(self, g):
        global _count
Exemplo n.º 5
0
Arquivo: hub.py Projeto: PlumpMath/evy
        signal.setitimer(signal.ITIMER_REAL, seconds)

    arm_alarm = alarm_itimer
else:
    try:
        import itimer

        arm_alarm = itimer.alarm
    except ImportError:

        def alarm_signal(seconds):
            signal.alarm(math.ceil(seconds))

        arm_alarm = alarm_signal

time = patcher.original('time')

READ = pyuv.UV_READABLE
WRITE = pyuv.UV_WRITABLE


def alarm_handler(signum, frame):
    import inspect
    raise RuntimeError("Blocking detector ALARMED at" +
                       str(inspect.getframeinfo(frame)))


def _signal_checker(handle, signum):
    pass  # XXX: how do I check for signals from pure python??

Exemplo n.º 6
0
Arquivo: tpool.py Projeto: inercia/evy
# limitations under the License.


import imp
import os
import sys

from evy import event
from evy.green import threads as greenthread
from evy import patcher
from evy import timeout
from evy.io.sockets import GreenSocket
from evy.io.pipes import GreenPipe


threading = patcher.original("threading")
Queue_module = patcher.original("Queue")
Queue = Queue_module.Queue
Empty = Queue_module.Empty

__all__ = ["execute", "Proxy", "killall"]

QUIET = True

_rfile = _wfile = None

_bytetosend = " ".encode()


def _signal_t2e():
    _wfile.write(_bytetosend)
Exemplo n.º 7
0
"""
Implements the standard threading module, using greenthreads.
"""

from evy import patcher
from evy.patched import thread
from evy.patched import time
from evy.support import greenlets as greenlet

__patched__ = [
    '_start_new_thread', '_allocate_lock', '_get_ident', '_sleep', 'local',
    'stack_size', 'Lock', 'currentThread', 'current_thread', '_after_fork',
    '_shutdown'
]

__orig_threading = patcher.original('threading')
__threadlocal = __orig_threading.local()

patcher.inject('threading', globals(), ('thread', thread), ('time', time))

del patcher

_count = 1


class _GreenThread(object):
    """Wrapper for GreenThread objects to provide Thread-like attributes
    and methods"""
    def __init__(self, g):
        global _count
        self._g = g
Exemplo n.º 8
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import imp
import os
import sys

from evy import event
from evy.green import threads as greenthread
from evy import patcher
from evy import timeout
from evy.io.sockets import GreenSocket
from evy.io.pipes import GreenPipe

threading = patcher.original('threading')
Queue_module = patcher.original('Queue')
Queue = Queue_module.Queue
Empty = Queue_module.Empty

__all__ = ['execute', 'Proxy', 'killall']

QUIET = True

_rfile = _wfile = None

_bytetosend = ' '.encode()


def _signal_t2e():
    _wfile.write(_bytetosend)
Exemplo n.º 9
0
profile_orig = __import__('profile')
__all__ = profile_orig.__all__

from evy.patcher import slurp_properties

slurp_properties(profile_orig, globals(), srckeys = dir(profile_orig))

import new
import sys
import traceback
import functools

from evy.green import threads as greenthread
from evy import patcher

thread = patcher.original('thread')  # non-monkeypatched module needed

#This class provides the start() and stop() functions
class Profile(profile_orig.Profile):
    base = profile_orig.Profile

    def __init__ (self, timer = None, bias = None):
        self.current_tasklet = greenthread.getcurrent()
        self.thread_id = thread.get_ident()
        self.base.__init__(self, timer, bias)
        self.sleeping = {}

    def __call__ (self, *args):
        "make callable, allowing an instance to be the profiler"
        r = self.dispatcher(*args)
Exemplo n.º 10
0
from weakref import proxy

import socket
from socket import socket as _original_socket

from evy.support import get_errno
from evy.hubs import get_hub
from evy.hubs import wait_read, wait_write
from evy.event import Event
from evy.io.utils import set_nonblocking
from evy.patcher import original
from evy.support.errors import last_file_error

import errno

_os_orig = original("os")


# Emulate _fileobject class in 3.x implementation
# Eventually this internal socket structure could be replaced with makefile calls.
try:
    _fileobject = socket._fileobject
except AttributeError:
    def _fileobject (sock, *args, **kwargs):
        return _original_socket.makefile(sock, *args, **kwargs)



__all__ = []