コード例 #1
0
ファイル: consumer.py プロジェクト: lanweichang/oio-sds
def _stop(client, server):
    try:
        client.wait()
    except greenlet.GreenletExit:
        pass
    except Exception:
        greenthread.kill(server, *sys.exc_info())
コード例 #2
0
ファイル: consumer.py プロジェクト: uneidel/oio-sds
def _stop(client, server):
    try:
        client.wait()
    except greenlet.GreenletExit:
        pass
    except Exception:
        greenthread.kill(server, *sys.exc_info())
コード例 #3
0
ファイル: wsgi.py プロジェクト: woome/drivel
 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))
コード例 #4
0
ファイル: misc.py プロジェクト: GunioRobot/heroshi
def reraise_errors(t, master_gt):
    try:
        return t.wait()
    except greenlet.GreenletExit:
        pass
    except Exception:
        greenthread.kill(master_gt, *sys.exc_info())
コード例 #5
0
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
コード例 #6
0
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
コード例 #7
0
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
コード例 #8
0
 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)
コード例 #9
0
 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)
コード例 #10
0
ファイル: np_watcher.py プロジェクト: intlabs/ovn-kubernetes
 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]
コード例 #11
0
ファイル: convenience.py プロジェクト: CaesarLinsa/Eventlet
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())
コード例 #12
0
ファイル: consumer.py プロジェクト: lanweichang/oio-sds
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())
コード例 #13
0
ファイル: consumer.py プロジェクト: uneidel/oio-sds
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())
コード例 #14
0
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())
コード例 #15
0
    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)
コード例 #16
0
ファイル: test_websocket.py プロジェクト: boothead/multivisor
    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()
コード例 #17
0
    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)
コード例 #18
0
ファイル: geventlet.py プロジェクト: Aayush-N/aynst
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())
コード例 #19
0
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())
コード例 #20
0
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
コード例 #21
0
ファイル: tpool.py プロジェクト: c0ns0le/zenoss-4
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
コード例 #22
0
ファイル: tpool.py プロジェクト: Mawaheb/Vesper-crm
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
コード例 #23
0
    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)
コード例 #24
0
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
コード例 #25
0
ファイル: test_websocket.py プロジェクト: boothead/multivisor
    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)
コード例 #26
0
ファイル: geventlet.py プロジェクト: timf/gunicorn
    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)
コード例 #27
0
    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)
コード例 #28
0
ファイル: utils.py プロジェクト: gluster/gluster-swift
    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)
コード例 #29
0
ファイル: test.py プロジェクト: thrawn01/apple
    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) )
コード例 #30
0
ファイル: coros_test.py プロジェクト: 2013Commons/HUE-SHARK
 def tearDown(self):
     super(TestActor, self).tearDown()
     greenthread.kill(self.actor._killer)
コード例 #31
0
ファイル: wsgi.py プロジェクト: edwardgeorge/drivel
        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)
コード例 #32
0
 def tearDown(self):
     super(TestActor, self).tearDown()
     greenthread.kill(self.actor._killer)
コード例 #33
0
ファイル: test.py プロジェクト: thrawn01/apple
 def tearDown(self):
     log.debug( "TestBase::tearDown()" )
     greenthread.kill(self.killer)
     eventlet.sleep(0)
     LimitedTestCase.tearDown( self )
コード例 #34
0
ファイル: connwatch.py プロジェクト: edwardgeorge/drivel
 def kill():
     p = proc_weakref()
     if p:
         greenthread.kill(p, *exc_args)