コード例 #1
0
ファイル: forsund.py プロジェクト: soszrg/forsun
def main():
    args = parser.parse_args()

    config.set("LOG_FILE", args.log_file)
    config.set("LOG_LEVEL", args.log_level)

    config.set("BIND_ADDRESS", args.bind_host)
    config.set("PORT", args.bind_port)
    config.set("HTTP_BIND", args.http_bind)

    config.set("STORE_DRIVER", args.driver)
    config.set("STORE_REDIS_HOST", args.driver_redis_host)
    config.set("STORE_REDIS_PORT", args.driver_redis_port)
    config.set("STORE_REDIS_DB", args.driver_redis_db)
    config.set("STORE_REDIS_PREFIX", args.driver_redis_prefix)
    config.set("STORE_REDIS_SERVER_ID", args.driver_redis_server_id)

    config.set("EXTENSION_PATH", args.extension_path)
    config.set("EXTENSIONS", args.extensions)


    if args.demon:
        p = multiprocessing.Process(target = serve, name=" ".join(sys.argv))
        p.start()
        if is_py3:
            atexit._clear()
        else:
            atexit._exithandlers = []
    else:
        serve(False)
コード例 #2
0
    def test_clear(self):
        a = [0]
        def inc():
            a[0] += 1

        atexit.register(inc)
        atexit._clear()
        atexit._run_exitfuncs()

        self.assertEqual(a[0], 0)
コード例 #3
0
def exit():
    """Exit subprocess, possibly after first clearing exit functions.

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    functions registered with atexit will be removed before exiting.
    (VPython support)

    """
    if no_exitfunc:
        import atexit
        atexit._clear()
    sys.exit(0)
コード例 #4
0
def delete_logs():
    if hasattr(atexit, "_clear"):
        atexit._clear()
    elif hasattr(atexit, "_exithandlers"):
        atexit._exithandlers[:] = []    # stop the logging module's exit handler
    
    for suffix in Logger.LEVELS:
        filename = Logger.DEFAULT_PREFIX + ".{0}_log".format(suffix)
        if os.path.exists(filename):
            handlers = logging.getLogger(Logger.DEFAULT_PREFIX + "." + suffix).handlers
            if handlers and handlers[0].stream:
                handlers[0].stream.close()
            os.remove(filename)
コード例 #5
0
ファイル: unit_tests.py プロジェクト: ilyakitaev/protlib2
def delete_logs():
    if hasattr(atexit, "_clear"):
        atexit._clear()
    elif hasattr(atexit, "_exithandlers"):
        atexit._exithandlers[:] = []    # stop the logging module's exit handler
    
    for suffix in Logger.LEVELS:
        filename = "unit_tests.{0}_log".format(suffix)
        if os.path.exists(filename):
            handlers = logging.getLogger("unit_tests." + suffix).handlers
            if handlers and handlers[0].stream:
                handlers[0].stream.close()
            os.remove(filename)
コード例 #6
0
ファイル: run.py プロジェクト: zhoumengfa/cpython
def exit():
    """Exit subprocess, possibly after first clearing exit functions.

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    functions registered with atexit will be removed before exiting.
    (VPython support)

    """
    if no_exitfunc:
        import atexit
        atexit._clear()
    capture_warnings(False)
    sys.exit(0)
コード例 #7
0
def test():
    for _ in range(999):
        args = [fargs() for _ in range(fint())]

        for f, a, k in args[fint():fint()]:
            atexit.register(f, *a, **k)

        if fint() == 0: atexit._clear()
        if fint() == 0: atexit._run_exitfuncs()

        for f, a, k in args[fint():fint()]:
            atexit.unregister(f)

        if fint() == 0: atexit._clear()
        if fint() == 0: atexit._run_exitfuncs()

        atexit._ncallbacks()
コード例 #8
0
ファイル: cv_util.py プロジェクト: JokinYang/Sudoku
def show_img(img: np.ndarray,
             win_name=None,
             ratio=0.5,
             wait_key=True) -> AnyStr:
    height, width, _ = img.shape
    win_name = str(win_name or random())
    cv.namedWindow(
        win_name,
        cv.WINDOW_KEEPRATIO | cv.WINDOW_NORMAL | cv.WINDOW_GUI_EXPANDED)
    if ratio:
        pass
        # img = resize(img, ratio=ratio)
    cv.imshow(win_name, img)
    cv.resizeWindow(win_name, int(width * ratio), int(height * ratio))
    if wait_key:
        atexit._clear()
        atexit.register(cv.waitKey)
    return win_name
コード例 #9
0
def initialize_components(augur_app, disable_housekeeper):
    master = None
    manager = None
    broker = None
    housekeeper = None
    worker_processes = []
    mp.set_start_method('forkserver', force=True)

    if not disable_housekeeper:
        logger.info("Booting manager")
        manager = mp.Manager()

        logger.info("Booting broker")
        broker = manager.dict()

        housekeeper = Housekeeper(broker=broker, augur_app=augur_app)

        controller = augur_app.config.get_section('Workers')

        for worker in controller.keys():
            if controller[worker]['switch']:
                for i in range(controller[worker]['workers']):
                    logger.info("Booting {} #{}".format(worker, i + 1))
                    worker_process = mp.Process(target=worker_start,
                                                name=f"{worker}_{i}",
                                                kwargs={
                                                    'worker_name':
                                                    worker,
                                                    'instance_number':
                                                    i,
                                                    'worker_port':
                                                    controller[worker]['port']
                                                },
                                                daemon=True)
                    worker_processes.append(worker_process)
                    worker_process.start()

    augur_app.manager = manager
    augur_app.broker = broker
    augur_app.housekeeper = housekeeper

    atexit._clear()
    atexit.register(exit, augur_app, worker_processes, master)
    return AugurGunicornApp(augur_app.gunicorn_options, augur_app=augur_app)
コード例 #10
0
def main():
    args = parser.parse_args()

    if args.conf:
        try:
            config.load_conf(args.conf)
        except Exception as e:
            print("load conf file error ", str(e))
            exit(1)

    if not args.nodemon:
        def run():
            try:
                server = ThriftServer()

                sys.stdin.close()
                sys.stdin = open(os.devnull)

                sys.stdout.close()
                sys.stdout = open(os.devnull, 'w')

                sys.stderr.close()
                sys.stderr = open(os.devnull, 'w')

                server.start()
            except Exception as e:
                print(e)
                exit(1)

        p = multiprocessing.Process(target=run, name=" ".join(sys.argv))
        p.start()
        atexit._clear()
    else:
        try:
            server = ThriftServer()
            server.start()
        except Exception as e:
            print(e)
            exit(1)
コード例 #11
0
ファイル: _test_atexit.py プロジェクト: za/cpython
 def tearDown(self):
     atexit._clear()
コード例 #12
0
ファイル: _test_atexit.py プロジェクト: za/cpython
 def setUp(self):
     atexit._clear()
コード例 #13
0
 def tearDown(self):
     sys.stdout = self.save_stdout
     sys.stderr = self.save_stderr
     atexit._clear()
コード例 #14
0
 def setUp(self):
     self.stream = io.StringIO()
     self.save_stdout, self.save_stderr = sys.stderr, sys.stdout
     sys.stdout = sys.stderr = self.stream
     atexit._clear()
コード例 #15
0
 def tearDown(self):
     sys.stdout = self.save_stdout
     sys.stderr = self.save_stderr
     atexit._clear()
コード例 #16
0
def tearDown(test):
    sys.stderr = test.real_stderr
    if hasattr(atexit, '_clear'):
        atexit._clear()
    else:
        del atexit._exithandlers[:]
コード例 #17
0
def fork():
    pid = orig_fork()
    if not pid:
        print("patched fork")
        atexit._clear()
    return pid
コード例 #18
0
 def quitting(self):
     self._finished = True
     atexit._clear()  # make sure we dont capture additional ctrl-c:s # pylint: disable=protected-access
     self._background.join()
     self.exit()
コード例 #19
0
ファイル: conftest.py プロジェクト: sashgorokhov/edp
def atexit_clear(tempdir):
    yield
    atexit._clear()
コード例 #20
0
 def setUp(self):
     self.save_stdout = sys.stdout
     self.save_stderr = sys.stderr
     self.stream = io.StringIO()
     sys.stdout = sys.stderr = self.stream
     atexit._clear()
コード例 #21
0
def main():
    args = parser.parse_args()

    if args.conf:
        try:
            config.load_conf(args.conf)
        except Exception as e:
            print("load conf file error ", str(e))
            exit(1)

    if args.log_file:
        config.set("LOG_FILE", args.log_file)
    if args.log_level:
        config.set("LOG_LEVEL", args.log_level)

    if args.bind_host:
        config.set("BIND_ADDRESS", args.bind_host)
    if args.bind_port:
        config.set("PORT", args.bind_port)
    if args.http_bind:
        config.set("HTTP_BIND", args.http_bind)

    if args.driver:
        config.set("STORE_DRIVER", args.driver)
    if args.store_mem_store_file:
        config.set("STORE_MEM_STORE_FILE", args.store_mem_store_file)
    if args.driver_redis_host:
        config.set("STORE_REDIS_HOST", args.driver_redis_host)
    if args.driver_redis_port:
        config.set("STORE_REDIS_PORT", args.driver_redis_port)
    if args.driver_redis_db:
        config.set("STORE_REDIS_DB", args.driver_redis_db)
    if args.driver_redis_password:
        config.set("STORE_REDIS_PASSWORD", args.driver_redis_password)
    if args.driver_redis_prefix:
        config.set("STORE_REDIS_PREFIX", args.driver_redis_prefix)
    if args.driver_redis_server_id:
        config.set("STORE_REDIS_SERVER_ID", args.driver_redis_server_id)

    if args.extension_path:
        config.set("EXTENSION_PATH", args.extension_path)
    if args.extensions:
        config.set("EXTENSIONS", args.extensions)

    if not args.nodemon:
        from ..forsun import Forsun

        def on_start(forsun):
            print("forsund started by pid %s" % p.pid)
            sys.stdin.close()
            sys.stdin = open(os.devnull)

            sys.stdout.close()
            sys.stdout = open(os.devnull, 'w')

            sys.stderr.close()
            sys.stderr = open(os.devnull, 'w')

        def run():
            try:
                forsun = Forsun()
                forsun.serve(on_start)
            except Exception as e:
                print(e)
                exit(1)

        p = multiprocessing.Process(target=run, name=" ".join(sys.argv))
        p.start()
        if is_py3:
            atexit._clear()
        else:
            atexit._exithandlers = []
    else:
        try:
            from ..forsun import Forsun
            forsun = Forsun()
            forsun.serve()
        except Exception as e:
            print(e)
            exit(1)
コード例 #22
0
                )
            logger.info('time: %s', f'{(time.time() - start)}s')
            logger.info('success rate: %s', successful / fetched)
    return True


if __name__ == '__main__':

    browser = pychrome.Browser()
    tab = list(
        filter(
            lambda tab: tab.id == '(D3876BF786C0B494B01CC04FFE420A2B)',
            browser.list_tab()
        )
    )[0]
    if tab.status != 'started':
        tab.start()
    while True:
        try:
            if main():
                atexit._clear()
                break
            atexit._run_exitfuncs()
            atexit._clear()
        except (MustExit, KeyboardInterrupt):
            sys.exit(255)
            break
        except Exception:
            logger.warning('Restarting!')
        time.sleep(10)
コード例 #23
0
 def tearDown(self):
     atexit._clear()
     self.sumo.action_log.log_io.flush_write_queues()
     self.milo.action_log.log_io.flush_write_queues()
     rmtree(self.tmpdir)