Пример #1
0
    def _do_operation(self, operation, flag, func, args, kwargs):
        # loop until we get a response from the operation
        while ioloop._go:
            try:
                ret = func(*args, **kwargs)
                break

            except __socket__.error, e:
                if operation == 'connect' and e.errno == errno.EISCONN: # transport endpoint is connected
                    return
                if (e.errno != errno.EWOULDBLOCK #Resource temporarily unavailable
                    and e.errno != errno.EINPROGRESS #Operation now in progress
                    and e.errno != errno.EALREADY
#                    and e.errno != errno.EMFILE #Too many open files
                ): #Too many open files
                    raise
                log.debug("Asynchronous socket is not ready for %r %r %r", operation, self, e)
                ioloop.coreloop().register(self.fileno(), flag)
    
                try:
                    # loop until we don't get a noop (which means we should be ready for our operation)
                    while True:
                        ret = ioloop.coreloop().switch()
                        if ioloop.IDLE and ret is ioloop.noop:
                            log.debug("noop")
                            continue
                        break
                finally:
                    ioloop.coreloop().unregister(self.fileno(), flag)
                if operation == 'connect':# and e.errno != errno.EMFILE:
                    # We don't want to retry connecting, so just return now
                    return
Пример #2
0
def main(num=1000, forever=False):
    while True:
        gls = []
        for i in xrange(num):
            while True:
                try:
                    s = socket()
                except pysocket.error, e:
                    if e.errno != 24:
                        raise
                    ioloop.coreloop().switch()
                else:
                    break
            s.connect(("127.0.0.1", 2424))
                
            gl = greenlet.greenlet(recvall)
            gls.append((i, s, gl))
            gl.switch(s, i)
        
        while gls:
            for i, s, gl in gls:
                if gl.dead:
                    gls.remove((i, s, gl))
                else:
                    gl.switch()

        if not forever:
            break
Пример #3
0
def timer():
    import threading
    t = threading.current_thread()
    if t not in _timerloops:
        l = timerloop(ioloop.coreloop())
        _timerloops[t] = l
    return _timerloops[t]