def _stop(client, server): try: client.wait() except greenlet.GreenletExit: pass except Exception: greenthread.kill(server, *sys.exc_info())
def watchconnection(sock, proc): """listen for EOF on socket.""" def watcher(sock, proc): fileno = "%s" % (sock.fileno(),) if proc(): proc().link(dothrow, greenthread.getcurrent()) else: return try: log('debug', 'watching connection %s for termination' ' at client end' % fileno) hubs.trampoline(sock, read=True) d = sock.read() if not d and bool(proc()): log('debug', 'terminating wsgi proc using closed sock %s' % fileno) greenthread.kill(proc(), ConnectionClosed()) except socket.error, e: if e[0] == errno.EPIPE: log('debug', 'got broken pipe on sock %s. terminating.' % fileno) if proc() is not None: greenthread.kill(proc(), ConnectionClosed()) else: log('debug', 'got error %s for sock %' % (e, fileno)) except IOError, e: if e.errno == errno.EPIPE: log('debug', 'got broken pipe on sock %s. terminating.' % fileno) if proc() is not None: greenthread.kill(proc(), ConnectionClosed()) else: log('debug', 'got error %s for sock %' % (e, fileno))
def reraise_errors(t, master_gt): try: return t.wait() except greenlet.GreenletExit: pass except Exception: greenthread.kill(master_gt, *sys.exc_info())
def killall(): global _setup_already, _rspq, _rsock, _wsock if not _setup_already: return # This yield fixes freeze in some scenarios eventlet.sleep(0) for thr in _threads: _reqq.put(None) for thr in _threads: thr.join() del _threads[:] # return any remaining results while (_rspq is not None) and not _rspq.empty(): try: (e, rv) = _rspq.get(block=False) e.send(rv) e = rv = None except Empty: pass if _coro is not None: greenthread.kill(_coro) if _rsock is not None: _rsock.close() _rsock = None if _wsock is not None: _wsock.close() _wsock = None _rspq = None _setup_already = False
def killall(): global _setup_already, _rspq, _rsock, _wsock if not _setup_already: return for thr in _threads: _reqq.put(None) for thr in _threads: thr.join() del _threads[:] # return any remaining results while not _rspq.empty(): try: (e, rv) = _rspq.get(block=False) e.send(rv) e = rv = None except Empty: pass if _coro is not None: greenthread.kill(_coro) _rsock.close() _wsock.close() _rsock = None _wsock = None _rspq = None _setup_already = False
def test_kill_n(self): gt = greenthread.spawn_n(passthru, 7) greenthread.kill(gt) self.assert_dead(gt) greenthread.sleep(0.001) self.assertEquals(_g_results, []) greenthread.kill(gt) self.assert_dead(gt)
def remove_namespace(self, namespace): np_watcher_thread = self._np_watcher_threads[namespace] greenthread.kill(np_watcher_thread) del self._np_watcher_threads[namespace] policy_names = [policy for (policy, ns) in self.np_ns_map.items() if namespace == ns] for policy_name in policy_names: del self.np_cache[policy_name]
def _stop_checker(t, server_gt, conn): try: try: t.wait() finally: conn.close() except greenlet.GreenletExit: pass except Exception: greenthread.kill(server_gt, *sys.exc_info())
def _eventlet_stop(client, server, beanstalk): try: try: client.wait() finally: beanstalk.close() except greenlet.GreenletExit: pass except Exception: greenthread.kill(server, *sys.exc_info())
def clear_up(self, module=None): greenthread.kill(self.killer) eventlet.sleep(0) try: hub = hubs.get_hub() num_readers = len(hub.get_readers()) num_writers = len(hub.get_writers()) assert num_readers == num_writers == 0 except AssertionError: print "ERROR: Hub not empty" print debug.format_hub_timers() print debug.format_hub_listeners() eventlet.sleep(0)
def tearDown(self): # self.timer.cancel() greenthread.kill(self.killer) eventlet.sleep(0) try: hub = hubs.get_hub() num_readers = len(hub.get_readers()) num_writers = len(hub.get_writers()) assert num_readers == num_writers == 0 except AssertionError, e: # set_trace() print "ERROR: Hub not empty" print debug.format_hub_timers() print debug.format_hub_listeners()
def _eventlet_stop(client, server, conn): """ Stop a greenlet handling a request and close its connection. This code is lifted from eventlet so as not to depend on undocumented functions in the library. """ try: try: client.wait() finally: conn.close() except greenlet.GreenletExit: pass except Exception: greenthread.kill(server, *sys.exc_info())
def killall(): global _setup_already, _rspq, _rsock, _wsock if not _setup_already: return for thr in _threads: _reqq.put(None) for thr in _threads: thr.join() del _threads[:] if _coro is not None: greenthread.kill(_coro) _rsock.close() _wsock.close() _rsock = None _wsock = None _rspq = None _setup_already = False
def killall(): global _setup_already, _rspq, _rfile, _wfile if not _setup_already: return for reqq, _ in _threads: reqq.put(None) for _, thr in _threads: thr.join() del _threads[:] if _coro is not None: greenthread.kill(_coro) _rfile.close() _wfile.close() _rfile = None _wfile = None _rspq = None _setup_already = False
def killall(): global _setup_already, _rspq, _rfile, _wfile if not _setup_already: return for thr in _threads: _reqq.put(None) for thr in _threads: thr.join() del _threads[:] if _coro is not None: greenthread.kill(_coro) _rfile.close() _wfile.close() _rfile = None _wfile = None _rspq = None _setup_already = False
def _spawn_server(self, **kwargs): """Spawns a new wsgi server with the given arguments. Sets self.port to the port of the server, and self.killer is the greenlet running it. Kills any previously-running server. """ if self.killer: greenthread.kill(self.killer) eventlet.sleep(0) app = self.config.make_wsgi_app() new_kwargs = dict(max_size=128, log=self.logfile) new_kwargs.update(kwargs) sock = eventlet.listen(('localhost', 0)) self.port = sock.getsockname()[1] self.killer = eventlet.spawn_n(wsgi.server, sock, app, **new_kwargs)
def killall(): global _setup_already, _reqq, _rspq, _rfile, _wfile if not _setup_already: return for i in _threads: _reqq.put(None) for thr in _threads: thr.join() _threads.clear() if _coro is not None: greenthread.kill(_coro) _rfile.close() _wfile.close() _rfile = None _wfile = None _reqq = None _rspq = None _setup_already = False
def spawn_server(self, **kwargs): """Spawns a new wsgi server with the given arguments. Sets self.port to the port of the server, and self.killer is the greenlet running it. Kills any previously-running server.""" if self.killer: greenthread.kill(self.killer) eventlet.sleep(0) app = self.config.make_wsgi_app() new_kwargs = dict(max_size=128, log=self.logfile) new_kwargs.update(kwargs) sock = eventlet.listen(('localhost', 0)) self.port = sock.getsockname()[1] self.killer = eventlet.spawn_n(wsgi.server, sock, app, **new_kwargs)
def run(self): self.socket.setblocking(1) pool = greenpool.GreenPool(self.worker_connections) acceptor = greenthread.spawn(self.acceptor, pool) while self.alive: self.notify() if self.ppid != os.getppid(): self.log.info("Parent changed, shutting down: %s" % self) greenthread.kill(acceptor, eventlet.StopServe) break eventlet.sleep(0.1) with eventlet.Timeout(self.timeout, False): pool.waitall() os._exit(3)
def terminate(self): """ Releases the threadpool's resources (OS threads, greenthreads, pipes, etc.) and renders it unusable. Don't call run_in_thread() or force_run_in_thread() after calling terminate(). """ self._alive = False if self.nthreads <= 0: return for _junk in range(self.nthreads): self._run_queue.put(None) for thr in self._threads: thr.join() self._threads = [] self.nthreads = 0 greenthread.kill(self._consumer_coro) self.rpipe.close() os.close(self.wpipe)
def spawn_server(self, **kwargs): """Spawns a new wsgi server with the given arguments. Sets self.port to the port of the server, and self.killer is the greenlet running it. Kills any previously-running server.""" eventlet.sleep(0) # give previous server a chance to start if self.killer: greenthread.kill(self.killer) eventlet.sleep(0) # give killer a chance to kill new_kwargs = dict(max_size=128, log=self.logfile, site=self.site) new_kwargs.update(kwargs) if 'sock' not in new_kwargs: new_kwargs['sock'] = eventlet.listen(('localhost', 0)) self.port = new_kwargs['sock'].getsockname()[1] self.killer = eventlet.spawn_n( wsgi.server, **new_kwargs) log.debug( "Server Spawned '%s:%s'" % ('localhost', self.port) )
def tearDown(self): super(TestActor, self).tearDown() greenthread.kill(self.actor._killer)
rfile = getattr(environ['wsgi.input'], 'rfile', None) request = Request(environ) proc = weakref.ref(greenthread.getcurrent()) body = str(request.body) if request.method == 'POST' else request.GET.get('body', '') user = self.authbackend(request) subs, msg, kw = self._path_to_subscriber(request.path) watcher = None if rfile and self.watch_connections: watcher = connwatch.spawn_from_pool(self.watcher_pool, rfile, proc, ConnectionClosed, '') try: with eventlet.Timeout(self.timeout): msgs = self.server.send(subs, msg, kw, user, request, proc).wait() except eventlet.Timeout, e: msgs = [] except ConnectionClosed, e: msgs = [] finally: if watcher: greenthread.kill(watcher) headers = [('Content-type', 'application/javascript'), ('Connection', 'close')] start_response('200 OK', headers) if 'jsonpcallback' in request.GET: msgs = '%s(%s)' % (request.GET['jsonpcallback'], json.dumps(msgs)) elif not isinstance(msgs, basestring): msgs = json.dumps(msgs) return [msgs+'\r\n'] def __call__(self, environ, start_response): return self.app(environ, start_response)
def tearDown(self): log.debug( "TestBase::tearDown()" ) greenthread.kill(self.killer) eventlet.sleep(0) LimitedTestCase.tearDown( self )
def kill(): p = proc_weakref() if p: greenthread.kill(p, *exc_args)