def test_nested_with_timeout(self): def func(): return api.with_timeout(0.2, api.sleep, 2, timeout_value=1) try: api.with_timeout(0.1, func) self.fail(u'Expected api.TimeoutError') except api.TimeoutError: pass
def test_pause_producing(self): self.conn.pauseProducing() self.conn.write('hi\r\n') result = with_timeout(DELAY * 10, self.conn.read, timeout_value='timed out') self.assertEqual('timed out', result)
def test_pauseresume_producing(self): self.conn.pauseProducing() call_after(DELAY * 5, self.conn.resumeProducing) self.conn.write('hi\r\n') result = with_timeout(DELAY * 10, self.conn.read, timeout_value='timed out') self.assertEqual('you said hi. BYE', result)
def test_send(self): event1 = Event() event2 = Event() spawn(event1.send, 'hello event1') eventlet.Timeout(0, ValueError('interrupted')) try: result = event1.wait() except ValueError: X = object() result = with_timeout(DELAY, event2.wait, timeout_value=X) assert result is X, 'Nobody sent anything to event2 yet it received %r' % (result, )
def func(): return api.with_timeout(0.2, api.sleep, 2, timeout_value=1)
def serve_from_child(sock, config, controller_pid): threads = config.get('threadpool_workers', 0) wsgi_application = api.named(config['app_factory'])(config) if config.get('coverage'): wsgi_application = FigleafCoverage(wsgi_application) if threads > 1: wsgi_application = ExecuteInThreadpool(wsgi_application) elif threads != 1: print "(%s) not using threads, installing eventlet cooperation monkeypatching" % ( os.getpid(), ) from eventlet import util util.wrap_socket_with_coroutine_socket() #util.wrap_pipes_with_coroutine_pipes() #util.wrap_threading_local_with_coro_local() host, port = sock.getsockname() access_log_file = config.get('access_log_file') if access_log_file is not None: access_log_file = open(access_log_file, 'a') max_age = 0 if config.get('max_age'): max_age = int(config.get('max_age')) server_event = coros.event() http_version = config.get('no_keepalive') and 'HTTP/1.0' or 'HTTP/1.1' try: wsgi_args = (sock, wsgi_application) wsgi_kwargs = {'log' : access_log_file, 'server_event' : server_event, 'max_http_version' : http_version} if config.get('no_keepalive'): wsgi_kwargs.update({'keepalive' : False}) if max_age: wsgi_kwargs.update({'timeout_value' : True}) api.with_timeout(max_age, wsgi.server, *wsgi_args, **wsgi_kwargs) else: wsgi.server(*wsgi_args, **wsgi_kwargs) except KeyboardInterrupt: pass except ExitChild: pass ## Set a deadman timer to violently kill the process if it doesn't die after ## some long timeout. signal.signal(signal.SIGALRM, deadman_timeout) signal.alarm(config['deadman_timeout']) ## Once we get here, we just need to handle outstanding sockets, not ## accept any new sockets, so we should close the server socket. sock.close() server = server_event.wait() last_outstanding = None if server.outstanding_requests: ## Let's tell our parent that we're dying try: os.kill(controller_pid, signal.SIGUSR1) except OSError, e: if not e.errno == errno.ESRCH: raise
def test_pauseresume_producing(self): self.conn.pauseProducing() call_after(DELAY*5, self.conn.resumeProducing) self.conn.write('hi\r\n') result = with_timeout(DELAY*10, self.conn.read, timeout_value='timed out') self.assertEqual('you said hi. BYE', result)
def test_pause_producing(self): self.conn.pauseProducing() self.conn.write('hi\r\n') result = with_timeout(DELAY*10, self.conn.read, timeout_value='timed out') self.assertEqual('timed out', result)
def check_timed_out(self, event, myproc, proc_finished_flag, queue): X = object() assert with_timeout(DELAY, event.wait, timeout_value=X) is X assert with_timeout(DELAY, queue.wait, timeout_value=X) is X assert with_timeout(DELAY, proc.waitall, [myproc], timeout_value=X) is X assert proc_finished_flag == [], proc_finished_flag
def func(): return with_timeout(0.2, sleep, 2, timeout_value=1)