python类exit()的实例源码

cli.py 文件源码 项目:Chattie 作者: chasinglogic 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def run(name, connector, inventory):
    """Run the bot.

    By default will run with the first available connector.
    """
    connectors = get_connectors()
    if len(connectors) == 0:
        print("ERROR: No available connectors!")
        os.exit(1)

    conn_pkg = connectors[0].load()
    for c in connectors:
        if c.name == connector:
            conn_pkg = c.load()

    inventories = get_inventories()
    if len(inventories) == 0:
        print("ERROR: No available inventories!")
        os.exit(1)

    for i in inventories:
        if i.name == inventory:
            inventory_pkg = i.load()

    commands = get_commands()
    print('comm', commands)
    inventory = inventory_pkg.Inventory()
    bot = Bot(name, inventory, commands)
    connector = conn_pkg.Connector(bot)
    print("Listening for messages...")
    connector.listen()
server_pool.py 文件源码 项目:ssr-ml 作者: AlphaBrock 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _loop(loop, dns_resolver, mgr):
        try:
            if mgr is not None:
                mgr.add_to_loop(loop)
            dns_resolver.add_to_loop(loop)
            loop.run()
        except (KeyboardInterrupt, IOError, OSError) as e:
            logging.error(e)
            import traceback
            traceback.print_exc()
            os.exit(0)
        except Exception as e:
            logging.error(e)
            import traceback
            traceback.print_exc()
nathan.py 文件源码 项目:nathan 作者: mseclab 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def error_msg(msg):
    print msg
    os.exit(1)
adb.py 文件源码 项目:nathan 作者: mseclab 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def run_adb_command(adb_type, command):
    if adb_type == "local":
        adb_cmd = EMULATOR_LOCAL_PTOOLS_DIR+ADB_CMD
    elif adb_type == "path":
        adb_cmd = ADB_CMD
    else:
        print_error("ADB type error!")
        os.exit(1)
    return run_command(adb_cmd + " " + command)
wspbus.py 文件源码 项目:autosub-bootstrapbill 作者: BenjV 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def block(self, interval=0.1):
        """Wait for the EXITING state, KeyboardInterrupt or SystemExit.

        This function is intended to be called only by the main thread.
        After waiting for the EXITING state, it also waits for all threads
        to terminate, and then calls os.execv if self.execv is True. This
        design allows another thread to call bus.restart, yet have the main
        thread perform the actual execv call (required on some platforms).
        """
        try:
            self.wait(states.EXITING, interval=interval, channel='main')
        except (KeyboardInterrupt, IOError):
            # The time.sleep call might raise
            # "IOError: [Errno 4] Interrupted function call" on KBInt.
            self.log('Keyboard Interrupt: shutting down bus')
            self.exit()
        except SystemExit:
            self.log('SystemExit raised: shutting down bus')
            self.exit()
            raise

        # Waiting for ALL child threads to finish is necessary on OS X.
        # See https://github.com/cherrypy/cherrypy/issues/581.
        # It's also good to let them all shut down before allowing
        # the main thread to call atexit handlers.
        # See https://github.com/cherrypy/cherrypy/issues/751.
        self.log('Waiting for child threads to terminate...')
        for t in threading.enumerate():
            # Validate the we're not trying to join the MainThread
            # that will cause a deadlock and the case exist when
            # implemented as a windows service and in any other case
            # that another thread executes cherrypy.engine.exit()
            if (
                    t != threading.currentThread() and
                    t.isAlive() and
                    not isinstance(t, threading._MainThread)
            ):
                # Note that any dummy (external) threads are always daemonic.
                if hasattr(threading.Thread, 'daemon'):
                    # Python 2.6+
                    d = t.daemon
                else:
                    d = t.isDaemon()
                if not d:
                    self.log('Waiting for thread %s.' % t.getName())
                    t.join()

        if self.execv:
            self._do_execv()
wspbus.py 文件源码 项目:watcher 作者: nosmokingbandit 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def block(self, interval=0.1):
        """Wait for the EXITING state, KeyboardInterrupt or SystemExit.

        This function is intended to be called only by the main thread.
        After waiting for the EXITING state, it also waits for all threads
        to terminate, and then calls os.execv if self.execv is True. This
        design allows another thread to call bus.restart, yet have the main
        thread perform the actual execv call (required on some platforms).
        """
        try:
            self.wait(states.EXITING, interval=interval, channel='main')
        except (KeyboardInterrupt, IOError):
            # The time.sleep call might raise
            # "IOError: [Errno 4] Interrupted function call" on KBInt.
            self.log('Keyboard Interrupt: shutting down bus')
            self.exit()
        except SystemExit:
            self.log('SystemExit raised: shutting down bus')
            self.exit()
            raise

        # Waiting for ALL child threads to finish is necessary on OS X.
        # See https://github.com/cherrypy/cherrypy/issues/581.
        # It's also good to let them all shut down before allowing
        # the main thread to call atexit handlers.
        # See https://github.com/cherrypy/cherrypy/issues/751.
        self.log("Waiting for child threads to terminate...")
        for t in threading.enumerate():
            # Validate the we're not trying to join the MainThread
            # that will cause a deadlock and the case exist when
            # implemented as a windows service and in any other case
            # that another thread executes cherrypy.engine.exit()
            if (
                    t != threading.currentThread() and
                    t.isAlive() and
                    not isinstance(t, threading._MainThread)
            ):
                # Note that any dummy (external) threads are always daemonic.
                if hasattr(threading.Thread, "daemon"):
                    # Python 2.6+
                    d = t.daemon
                else:
                    d = t.isDaemon()
                if not d:
                    self.log("Waiting for thread %s." % t.getName())
                    t.join()

        if self.execv:
            self._do_execv()


问题


面经


文章

微信
公众号

扫码关注公众号