Example #1
0
def wait_write(fileno, timeout=-1, timeout_exc=_socket.timeout('timed out')):
    evt = core.write_event(fileno, _wait_helper, timeout, (getcurrent(), timeout_exc))
    try:
        switch_result = get_hub().switch()
        assert evt is switch_result, 'Invalid switch into wait_write(): %r' % (switch_result, )
    finally:
        evt.cancel()
Example #2
0
def wait_write(fileno,
               timeout=None,
               timeout_exc=timeout('timed out'),
               event=None):
    """Block the current greenlet until *fileno* is ready to write.

    If *timeout* is non-negative, then *timeout_exc* is raised after *timeout* second has passed.
    By default *timeout_exc* is ``socket.timeout('timed out')``.

    If :func:`cancel_wait` is called, raise ``socket.error(EBADF, 'File descriptor was closed in another greenlet')``.
    """
    if event is None:
        event = core.write_event(fileno, _wait_helper, timeout,
                                 (getcurrent(), timeout_exc))
    else:
        assert event.callback == _wait_helper, event.callback
        assert event.arg is None, 'This event is already used by another greenlet: %r' % (
            event.arg, )
        event.arg = (getcurrent(), timeout_exc)
        event.add(timeout)
    try:
        switch_result = get_hub().switch()
        assert event is switch_result, 'Invalid switch into wait_write(): %r' % (
            switch_result, )
    finally:
        event.arg = None
        event.cancel()
Example #3
0
def select(rlist, wlist, xlist, timeout=None):
    """An implementation of :meth:`select.select` that blocks only the current greenlet.

    Note: *xlist* is ignored.
    """
    hub = get_hub()
    current = getcurrent()
    assert hub is not current, 'do not call blocking functions from the mainloop'
    allevents = []
    timeout = Timeout.start_new(timeout)
    try:
        try:
            for readfd in rlist:
                allevents.append(
                    core.read_event(get_fileno(readfd),
                                    _select_callback,
                                    arg=(current, readfd)))
            for writefd in wlist:
                allevents.append(
                    core.write_event(get_fileno(writefd),
                                     _select_callback,
                                     arg=(current, writefd)))
        except IOError, ex:
            raise error(*ex.args)
        try:
            result = hub.switch()
        except Timeout, ex:
            if ex is not timeout:
                raise
            return [], [], []
def wait_write(fileno, timeout=-1):
    evt = write_event(fileno, _wait_helper, timeout, getcurrent())
    try:
        switch_result = get_hub().switch()
        assert evt is switch_result, 'Invalid switch into wait_write(): %r' % (switch_result, )
    finally:
        evt.cancel()
Example #5
0
def wait_write(fileno, timeout=-1, timeout_exc=_socket.timeout('timed out')):
    evt = core.write_event(fileno, _wait_helper, timeout,
                           (getcurrent(), timeout_exc))
    try:
        switch_result = get_hub().switch()
        assert evt is switch_result, 'Invalid switch into wait_write(): %r' % (
            switch_result, )
    finally:
        evt.cancel()
Example #6
0
def select(rlist, wlist, xlist, timeout=None):
    """An implementation of :meth:`select.select` that blocks only the current greenlet.

    Note: *xlist* is ignored.
    """
    allevents = []
    timeout = Timeout.start_new(timeout)
    result = SelectResult()
    try:
        try:
            for readfd in rlist:
                allevents.append(core.read_event(get_fileno(readfd), result.update, arg=readfd))
            for writefd in wlist:
                allevents.append(core.write_event(get_fileno(writefd), result.update, arg=writefd))
        except IOError, ex:
            raise error(*ex.args)
        result.event.wait(timeout=timeout)
        return result.read, result.write, []
Example #7
0
def wait_write(fileno, timeout=None, timeout_exc=timeout('timed out'), event=None):
    """Block the current greenlet until *fileno* is ready to write.

    If *timeout* is non-negative, then *timeout_exc* is raised after *timeout* second has passed.
    By default *timeout_exc* is ``socket.timeout('timed out')``.

    If :func:`cancel_wait` is called, raise ``socket.error(EBADF, 'File descriptor was closed in another greenlet')``.
    """
    if event is None:
        event = core.write_event(fileno, _wait_helper, timeout, (getcurrent(), timeout_exc))
    else:
        assert event.callback == _wait_helper, event.callback
        assert event.arg is None, 'This event is already used by another greenlet: %r' % (event.arg, )
        event.arg = (getcurrent(), timeout_exc)
        event.add(timeout)
    try:
        switch_result = get_hub().switch()
        assert event is switch_result, 'Invalid switch into wait_write(): %r' % (switch_result, )
    finally:
        event.arg = None
        event.cancel()
Example #8
0
def select(rlist, wlist, xlist, timeout=None):
    """An implementation of :meth:`select.select` that blocks only the current greenlet.

    Note: *xlist* is ignored.
    """
    hub = get_hub()
    current = getcurrent()
    assert hub is not current, 'do not call blocking functions from the mainloop'
    allevents = []
    timeout = Timeout.start_new(timeout)
    try:
        try:
            for readfd in rlist:
                allevents.append(core.read_event(get_fileno(readfd), _select_callback, arg=(current, readfd)))
            for writefd in wlist:
                allevents.append(core.write_event(get_fileno(writefd), _select_callback, arg=(current, writefd)))
        except IOError, ex:
            raise error(*ex.args)
        try:
            result = hub.switch()
        except Timeout, ex:
            if ex is not timeout:
                raise
            return [], [], []
Example #9
0
def select(rlist, wlist, xlist, timeout=None):
    """An implementation of :meth:`select.select` that blocks only the current greenlet.

    Note: *xlist* is ignored.
    """
    allevents = []
    timeout = Timeout.start_new(timeout)
    result = SelectResult()
    try:
        try:
            for readfd in rlist:
                allevents.append(
                    core.read_event(get_fileno(readfd),
                                    result.update,
                                    arg=readfd))
            for writefd in wlist:
                allevents.append(
                    core.write_event(get_fileno(writefd),
                                     result.update,
                                     arg=writefd))
        except IOError, ex:
            raise error(*ex.args)
        result.event.wait(timeout=timeout)
        return result.read, result.write, []
Example #10
0
 def notify(self, msg):
     self.out_buff.append(msg + "\n")
     core.write_event(self.wfile.fileno(), self._cb_notify_write)