當前位置: 首頁>>代碼示例>>Python>>正文


Python gevent.kill方法代碼示例

本文整理匯總了Python中gevent.kill方法的典型用法代碼示例。如果您正苦於以下問題:Python gevent.kill方法的具體用法?Python gevent.kill怎麽用?Python gevent.kill使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gevent的用法示例。


在下文中一共展示了gevent.kill方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: detach

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def detach(self):
        if self._has_destroy:
            return
        super().detach()
        if self._auto_disconnect_greenlet:
            gevent.kill(self._auto_disconnect_greenlet)
            self._auto_disconnect_greenlet = None

        if self.videocall_user:
            self._plugin.user_dao.del_by_username(self.videocall_user.username)
            self.videocall_user.handle = None
            self.videocall_user = None

        if self.backend_handle:
            backend_handle = self.backend_handle
            self.backend_handle = None
            backend_handle.detach() 
開發者ID:OpenSight,項目名稱:janus-cloud,代碼行數:19,代碼來源:videocall.py

示例2: on_close

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def on_close(self, handle_id):
        self.backend_handle = None #detach with backend handle

        if self._auto_disconnect_greenlet:
            gevent.kill(self._auto_disconnect_greenlet)
            self._auto_disconnect_greenlet = None

        if self.videocall_user and self.videocall_user.incall:
            self.videocall_user.peer_name = ''
            self.videocall_user.incall = False
            self.videocall_user.utime = time.time()
            self._plugin.user_dao.update(self.videocall_user.peer_name)

            hangup_event_data = {
                'videocall': 'event',
                'result' : {
                    "event" : "hangup",
                    "username" : self.videocall_user.username,
                    "reason" : "backend handle closed"
                }
            }
            self._push_plugin_event(hangup_event_data, None, None) 
開發者ID:OpenSight,項目名稱:janus-cloud,代碼行數:24,代碼來源:videocall.py

示例3: destroy

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def destroy(self):
        if self.state == BACKEND_SESSION_STATE_DESTROYED:
            return
        self.state = BACKEND_SESSION_STATE_DESTROYED
        if _sessions.get(self.url) == self:
            _sessions.pop(self.url)

        if self._auto_destroy_greenlet:
            gevent.kill(self._auto_destroy_greenlet)
            self._auto_destroy_greenlet = None

        for handle in self._handles.values():
            handle.on_close()
        self._handles.clear()

        if self._ws_client:
            try:
                self._ws_client.close()
            except Exception:
                pass
            self._ws_client = None 
開發者ID:OpenSight,項目名稱:janus-cloud,代碼行數:23,代碼來源:backend_session.py

示例4: _run

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def _run(self):
        # Bind greenlet-local logging context.
        self.log = log.new(account_id=self.account_id, folder=self.folder_name,
                           provider=self.provider_name)
        # eagerly signal the sync status
        self.heartbeat_status.publish()

        try:
            self.update_folder_sync_status(lambda s: s.start_sync())
        except IntegrityError:
            # The state insert failed because the folder ID ForeignKey
            # was no longer valid, ie. the folder for this engine was deleted
            # while we were starting up.
            # Exit the sync and let the monitor sort things out.
            log.info("Folder state loading failed due to IntegrityError",
                     folder_id=self.folder_id, account_id=self.account_id)
            raise MailsyncDone()

        # NOTE: The parent ImapSyncMonitor handler could kill us at any
        # time if it receives a shutdown command. The shutdown command is
        # equivalent to ctrl-c.
        while True:
            retry_with_logging(self._run_impl, account_id=self.account_id,
                               provider=self.provider_name, logger=log) 
開發者ID:nylas,項目名稱:sync-engine,代碼行數:26,代碼來源:generic.py

示例5: attach_handle

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def attach_handle(self, plugin_package_name, opaque_id=None, handle_listener=None):
        """

        :param plugin_pacakge_name:  str plugin package name
        :param opaque_id:   str opaque id
        :param handle_listener: handle related  callback listener which cannot block
        :return: BackendHandle object
        """
        if self.state == BACKEND_SESSION_STATE_DESTROYED:
            raise JanusCloudError('Session has destroy for Janus server: {}'.format(self.url),
                                  JANUS_ERROR_SERVICE_UNAVAILABLE)

        attach_request_msg = create_janus_msg('attach', plugin=plugin_package_name)
        if opaque_id:
            attach_request_msg['opaque_id'] = opaque_id

        response = self.send_request(attach_request_msg)  # would block for IO
        if response['janus'] == 'success':
             handle_id = response['data']['id']
        elif response['janus'] == 'error':
            raise JanusCloudError(
                'attach error for Janus server {} with reason {}'.format(self.url, response['error']['reason']),
                response['error']['code'])
        else:
            raise JanusCloudError(
                'attach error for Janus server: {} with invalid response {}'.format(self.url, response),
                JANUS_ERROR_BAD_GATEWAY)

        # check again when wake up from block IO
        if self.state == BACKEND_SESSION_STATE_DESTROYED:
            raise JanusCloudError('Session has destroy for Janus server: {}'.format(self.url),
                                  JANUS_ERROR_SERVICE_UNAVAILABLE)

        handle = BackendHandle(handle_id, plugin_package_name, self,
                               opaque_id=opaque_id, handle_listener=handle_listener)
        self._handles[handle_id] = handle
        if self._auto_destroy_greenlet:
            gevent.kill(self._auto_destroy_greenlet)
            self._auto_destroy_greenlet = None
        return handle 
開發者ID:OpenSight,項目名稱:janus-cloud,代碼行數:42,代碼來源:backend_session.py

示例6: gevent_stop

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def gevent_stop(self):
        """
        Helper method to stop the node for gevent-based applications.
        """
        import gevent
        gevent.kill(self._poller_greenlet)
        self.remove()
        self._select = select.select 
開發者ID:closeio,項目名稱:redis-hashring,代碼行數:10,代碼來源:__init__.py

示例7: _watch_progress

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def _watch_progress(handler):
    """Context manager for creating a unix-domain socket and listen for
    ffmpeg progress events.

    The socket filename is yielded from the context manager and the
    socket is closed when the context manager is exited.

    Args:
        handler: a function to be called when progress events are
            received; receives a ``key`` argument and ``value``
            argument. (The example ``show_progress`` below uses tqdm)

    Yields:
        socket_filename: the name of the socket file.
    """
    with _tmpdir_scope() as tmpdir:
        socket_filename = os.path.join(tmpdir, 'sock')
        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        with contextlib.closing(sock):
            sock.bind(socket_filename)
            sock.listen(1)
            child = gevent.spawn(_do_watch_progress, socket_filename, sock, handler)
            try:
                yield socket_filename
            except:
                gevent.kill(child)
                raise 
開發者ID:kkroening,項目名稱:ffmpeg-python,代碼行數:29,代碼來源:show_progress.py

示例8: terminate

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def terminate():
    """Terminate all greenlets.
    """
    gevent.kill(produce_danmaku)
    gevent.kill(consume_danmaku)
    gevent.kill(heartbeat) 
開發者ID:OctavianLee,項目名稱:Barrage,代碼行數:8,代碼來源:produce_and_consume.py

示例9: exit

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def exit(self, signal=None):
        """ Handle an exit request """
        self.logger.info("{} {}".format(signal, "*" * 80))
        # Kill the top level greenlet
        gevent.kill(gevent.hub.get_hub().parent) 
開發者ID:simplecrypto,項目名稱:powerpool,代碼行數:7,代碼來源:main.py

示例10: destroy

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def destroy(self):
        if self.connected:
            log.debug("Disconnecting")
            self.role.stack.disconnect()
            self.role = None

        if self.socket_handler is not None:
            log.debug("Connection quit(), killing remaining connection threads")
            gevent.kill(self.socket_handler_thread)
            self.socket_handler = None
            self.socket_handler_thread = None

        if self.event_handler is not None:
            self.event_handler.__del__()
            self.event_handler = None 
開發者ID:nccgroup,項目名稱:BLESuite,代碼行數:17,代碼來源:core.py

示例11: on_open

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def on_open(self):
        if self.ws.protocol is None or (
                GRAPHQL_SUBSCRIPTIONS not in self.ws.protocol):
            self.ws.close(1002)

        def keep_alive_callback():
            if not self.ws.closed:
                self.send_keep_alive()
            else:
                gevent.kill(keep_alive_timer)

        if self.keep_alive:
            keep_alive_timer = gevent.spawn(self.timer, keep_alive_callback,
                                            self.keep_alive) 
開發者ID:hballard,項目名稱:graphql-python-subscriptions,代碼行數:16,代碼來源:subscription_transport_ws.py

示例12: async_raise_in_main_thread

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def async_raise_in_main_thread(exc, use_concurrent_loop=True):
    """
    Uses a unix signal to raise an exception to be raised in the main thread.
    """

    from plumbum import local
    pid = os.getpid()
    if not REGISTERED_SIGNAL:
        raise NotInitialized()

    # sometimes the signal isn't caught by the main-thread, so we should try a few times (WEKAPP-14543)
    def do_signal(raised_exc):
        global LAST_ERROR
        if LAST_ERROR is not raised_exc:
            _logger.debug("MainThread took the exception - we're done here")
            if use_concurrent_loop:
                raiser.stop()
            return

        _logger.info("Raising %s in main thread", type(LAST_ERROR))
        local.cmd.kill("-%d" % REGISTERED_SIGNAL, pid)

    if use_concurrent_loop:
        from .concurrency import concurrent
        raiser = concurrent(do_signal, raised_exc=exc, loop=True, sleep=30, daemon=True, throw=False)
        raiser.start()
    else:
        do_signal(exc) 
開發者ID:weka-io,項目名稱:easypy,代碼行數:30,代碼來源:sync.py

示例13: _rimt

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def _rimt(exc):
        _logger.info('YELLOW<<killing main thread greenlet>>')
        main_thread_greenlet = threading.main_thread()._greenlet
        orig_throw = main_thread_greenlet.throw

        # we must override "throw" method so exception will be raised with the original traceback
        def throw(*args):
            if len(args) == 1:
                ex = args[0]
                return orig_throw(ex.__class__, ex, ex.__traceback__)
            return orig_throw(*args)
        main_thread_greenlet.throw = throw
        gevent.kill(main_thread_greenlet, exc)
        _logger.debug('exiting the thread that failed')
        raise exc 
開發者ID:weka-io,項目名稱:easypy,代碼行數:17,代碼來源:sync.py

示例14: kill_this_process

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def kill_this_process(graceful=False):
    from plumbum import local
    pid = os.getpid()
    if graceful:
        flag = '-HUP'
    else:
        flag = '-9'
    local.cmd.kill(flag, pid) 
開發者ID:weka-io,項目名稱:easypy,代碼行數:10,代碼來源:sync.py

示例15: startWeb

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import kill [as 別名]
def startWeb(p,resourcePath,nonesym,timec,timebg,btc,btbg,etc,etbg,showetflag,showbtflag):
    global port, process, static_path, nonesymbol, timecolor, timebackground, btcolor, btbackground, etcolor, etbackground, showet, showbt
    port = p
    static_path = resourcePath
    nonesymbol = nonesym
    timecolor = timec
    timebackground = timebg
    btcolor = btc
    btbackground = btbg
    etcolor = etc
    etbackground = etbg
    showet = showetflag
    showbt = showbtflag
    if psystem() != 'Windows':
        gsignal(SIGQUIT, kill)

    process = mp.Process(name='WebLCDs',target=work,args=(
        port,
        resourcePath,
        nonesym,
        timec,
        timebg,
        btc,
        btbg,
        etc,
        etbg,
        showetflag,
        showbtflag,))
    process.start()
    
    libtime.sleep(4)
    
    if process.is_alive():    
        # check successful start
        url = "http://127.0.0.1:" + str(port) + "/status"
        r = rget(url,timeout=2)
        
        if r.status_code == 200:
            return True
        else:
            return False
    else:
        return False 
開發者ID:artisan-roaster-scope,項目名稱:artisan,代碼行數:45,代碼來源:weblcds.py


注:本文中的gevent.kill方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。