• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python multiprocessing.set_start_method函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中multiprocessing.set_start_method函数的典型用法代码示例。如果您正苦于以下问题:Python set_start_method函数的具体用法?Python set_start_method怎么用?Python set_start_method使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了set_start_method函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: run

def run(args):
    # create dummy environment to be able to create model
    env = gym.make(args.environment)
    assert isinstance(env.observation_space, Box)
    assert isinstance(env.action_space, Discrete)
    print("Observation space:", env.observation_space)
    print("Action space:", env.action_space)

    # create main model
    model = create_model(env, args)
    model.summary()
    env.close()

    # for better compatibility with Theano and Tensorflow
    multiprocessing.set_start_method('spawn')

    # create shared buffer for sharing weights
    blob = pickle.dumps(model.get_weights(), pickle.HIGHEST_PROTOCOL)
    shared_buffer = Array('c', len(blob))
    shared_buffer.raw = blob

    # force runner processes to use cpu
    os.environ["CUDA_VISIBLE_DEVICES"] = ""

    # create fifos and threads for all runners
    fifos = []
    for i in range(args.num_runners):
        fifo = Queue(args.queue_length)
        fifos.append(fifo)
        process = Process(target=runner, args=(shared_buffer, fifo, args))
        process.start()

    # start trainer in main thread
    trainer(model, fifos, shared_buffer, args)
开发者ID:tambetm,项目名称:gymexperiments,代码行数:34,代码来源:a2c.py


示例2: wrapper

 def wrapper(*args, **kwargs):
     out = func(*args, **kwargs)
     if sys.version_info > (3, 4):
         mp.set_start_method('spawn', force=True)
         func(*args, **kwargs)
         mp.set_start_method('fork', force=True)
     return out
开发者ID:Bjoux2,项目名称:keras,代码行数:7,代码来源:data_utils_test.py


示例3: main

def main():
    mp.set_start_method('spawn')
    q = mp.Queue()
    p = mp.Process(target=foo, args=(q,))
    p.start()
    print(q.get())
    p.join()
开发者ID:showa-yojyo,项目名称:bin,代码行数:7,代码来源:mp04start.py


示例4: compute_topological_summary

    def compute_topological_summary(self):
        """
        For each in self.outliers generate cleaned_points. Then construct
        GeometricComplex(cleaned_points) and compute its persistant 0-th
        homology.

        We save the 0-persistence pairs in the _list_
        self.persistence_pairs.

        persistence_pairs[outlier] contains dictionary with self-explaining
        keys:
        x_filtration_H0
        x_inv_filtration_H0
        y_filtration_H0
        y_inv_filtration_H0

        values are arrays of persistance pairs
        """

        mproc.set_start_method('forkserver')
        arguments = [i for i in range(len(self.outliers))]
        with mproc.Pool(processes=int(mproc.cpu_count()/2)) as pool:
            results = pool.map(self.single_outlier, arguments)

        self.extrema = [x[0] for x in results]
        self.persistence_pairs = [x[1] for x in results]
开发者ID:abulak,项目名称:TDA-Cause-Effect-Pairs,代码行数:26,代码来源:TDA_mprocess.py


示例5: crack

def crack(target_hash, salt, seed_str, num_proc):
    mp.set_start_method('spawn')
    
    #total_count = Counter(0)
    #pool = mp.Pool(initializer=init, initargs=(total_count,), processes=num_proc)
    
    #part_crack_helper = partial(crack_helper, target_hash=target_hash, salt=salt)
    
    try:
        #pool.map(part_crack_helper, product(seed_str, repeat=4))
        #pool.close()
        #pool.join()

        processes = []
        shift_interval = int(len(seed_str) / num_proc)
        pt_len = 6
        for i in range(0, num_proc):
            seed_str = ''.join(shift_array(list(seed_str), shift_interval))
            p = mp.Process(target=crack_helper_proc, args=(product(seed_str, repeat=pt_len), target_hash, salt))
            p.start()
            print("pid: %d started using seed str: %s" % (p.pid, seed_str))
            processes.append(p)

        for p in processes:
            p.join()

    except KeyboardInterrupt:
        #pool.terminate()
        #pool.join()

        for p in processes:
            p.terminate()
            p.join
开发者ID:whiteSkar,项目名称:crypto,代码行数:33,代码来源:crack_SHA1_6_alphanumeric_upper_lower_special_multiprocess.py


示例6: __init__

    def __init__(self, p_max_items_by_queue=50000, p_forkserver=False, p_log_every=10000):
        """Class creation"""
        logger = logging.getLogger('swallow')

        if p_forkserver:
            mp.set_start_method('forkserver')

        self.readers = None
        self.writer = None
        self.writer_store_args = None
        self.process = None
        self.process_args = None
        if p_max_items_by_queue is None:
            self.in_queue = JoinableQueue()
            self.out_queue = JoinableQueue()
        else:
            if (sys.platform.lower() == 'darwin'):
                logger.warn("As running Swallow on a MacOS env, the number of items is limited to 32767.")
                p_max_items_by_queue = 32767
            self.in_queue = JoinableQueue(p_max_items_by_queue)
            self.out_queue = JoinableQueue(p_max_items_by_queue)

        self.counters = {
            'nb_items_processed': Value('i', 0),
            'nb_items_error': Value('i', 0),
            'nb_items_scanned': Value('i', 0),
            'nb_items_stored': Value('i', 0),
            'whole_storage_time': Value('f', 0),
            'bulk_storage_time': Value('f', 0),
            'whole_process_time': Value('f', 0),
            'real_process_time': Value('f', 0),
            'idle_process_time': Value('f', 0),
            'scan_time': Value('f', 0),
            'log_every': p_log_every
        }
开发者ID:pagesjaunes,项目名称:swallow,代码行数:35,代码来源:Swallow.py


示例7: run

def run():

    # ask user for difficulty
    q_app = QtWidgets.QApplication([])
    q_widget = QtWidgets.QWidget()
    dialog = QtWidgets.QMessageBox(q_widget)
    dialog.addButton('Easy', QtWidgets.QMessageBox.ActionRole)
    dialog.addButton('Medium', QtWidgets.QMessageBox.ActionRole)
    dialog.addButton('Hard', QtWidgets.QMessageBox.ActionRole)
    dialog.addButton('Impossible', QtWidgets.QMessageBox.ActionRole)
    dialog.setText('Choose difficulty:')
    ret = dialog.exec_()

    easy, medium, hard, impossible = range(4)
    sim_time = None
    if ret == easy:
        sim_time = 1
    elif ret == medium:
        sim_time = 3
    elif ret == hard:
        sim_time = 5
    elif ret == impossible:
        sim_time = 8

    mp.set_start_method('spawn')
    gui_process = mp.Process(target=start_client.main)
    gui_process.start()

    run_game.main(BlackAgent='human', WhiteAgent='monte_carlo',
                  sim_time=sim_time, gui=True)
开发者ID:andysalerno,项目名称:reversi_ai,代码行数:30,代码来源:start_server_and_client.py


示例8: __init__

    def __init__(self,
                 project_dir=None,
                 max_training_processes=1,
                 response_log=None,
                 emulation_mode=None,
                 remote_storage=None,
                 component_builder=None,
                 model_server=None,
                 wait_time_between_pulls=None):
        self._training_processes = max(max_training_processes, 1)
        self._current_training_processes = 0
        self.responses = self._create_query_logger(response_log)
        self.project_dir = config.make_path_absolute(project_dir)
        self.emulator = self._create_emulator(emulation_mode)
        self.remote_storage = remote_storage
        self.model_server = model_server
        self.wait_time_between_pulls = wait_time_between_pulls

        if component_builder:
            self.component_builder = component_builder
        else:
            self.component_builder = ComponentBuilder(use_cache=True)

        self.project_store = self._create_project_store(project_dir)

        # tensorflow sessions are not fork-safe,
        # and training processes have to be spawned instead of forked. See
        # https://github.com/tensorflow/tensorflow/issues/5448#issuecomment
        # -258934405
        multiprocessing.set_start_method('spawn', force=True)

        self.pool = ProcessPool(self._training_processes)
开发者ID:marami52,项目名称:rasa_nlu,代码行数:32,代码来源:data_router.py


示例9: scope_session

def scope_session():
    if int(platform.python_version_tuple()[0]) >= 3:
        multiprocessing.set_start_method('forkserver')
        p = multiprocessing.Process(target=dummy_func)
        p.start()
        p.join()
    yield
开发者ID:asi1024,项目名称:chainer,代码行数:7,代码来源:conftest.py


示例10: test_transmission

    def test_transmission(self):
        import multiprocessing as mp
        if hasattr(mp, 'set_start_method'):
            mp.set_start_method('spawn')

        iq = mp.Queue()
        oq = mp.Queue()
        portName = 'TestVirtualPorts.%i' % time.time()
        senderProc = mp.Process(target=SenderProc, args=(oq, iq, portName))
        senderProc.start()

        # handshake
        self.assertEqual(iq.get(), 'init')  # virtual midi port is now open

        # Supposedly you can't just open a virtual port by name from
        # within the same proc or proc group? Anyway opening by index
        # works.
        device = RtMidiIn()
        for i in range(device.getPortCount()):
            if device.getPortName(i) == portName:
                device.openPort(i)
                break
        self.assertTrue(device.isPortOpen())

        # collect messages and print progress
        self.messages = []
        self.last_s = ''

        def put(m):
            self.messages.append(m)
            if len(self.messages) % 10 == 0:
                sys.stdout.write('\b' * len(self.last_s))  # backspace
                self.last_s = '%s: Received message %i / 32640' % (__name__, len(self.messages))
                sys.stdout.write(self.last_s)
                # sys.stdout.write('.')
                sys.stdout.flush()

        oq.put('start')
        for i in range(128):
            for j in range(1, 128):
                msg = device.getMessage(1000)
                self.assertTrue(msg is not None)
                self.assertTrue(msg.isNoteOn())
                self.assertEqual(msg.getNoteNumber(), i)
                self.assertEqual(msg.getVelocity(), j)
                put(msg)
                oq.put('next')

        for i in range(128):
            for j in range(128):
                msg = device.getMessage(1000)
                self.assertTrue(msg is not None)
                self.assertTrue(msg.isController())
                self.assertEqual(msg.getControllerNumber(), i)
                self.assertEqual(msg.getControllerValue(), j)
                put(msg)
                oq.put('next')

        self.assertEqual(len(self.messages), 32640)
        oq.put('done')
开发者ID:patrickkidd,项目名称:pyrtmidi,代码行数:60,代码来源:test_rtmidi.py


示例11: __init__

    def __init__(self, p_max_items_by_queue=50000, p_forkserver=False, p_log_every=10000):
        """Class creation"""
        if p_forkserver:
            mp.set_start_method('forkserver')

        self.readers = None
        self.writer = None
        self.writer_store_args = None
        self.process = None
        self.process_args = None
        if p_max_items_by_queue is None:
            self.in_queue = JoinableQueue()
            self.out_queue = JoinableQueue()
        else:
            self.in_queue = JoinableQueue(p_max_items_by_queue)
            self.out_queue = JoinableQueue(p_max_items_by_queue)

        self.counters = {
            'nb_items_processed': Value('i', 0),
            'nb_items_error': Value('i', 0),
            'nb_items_scanned': Value('i', 0),
            'nb_items_stored': Value('i', 0),
            'whole_storage_time': Value('f', 0),
            'bulk_storage_time': Value('f', 0),
            'whole_process_time': Value('f', 0),
            'real_process_time': Value('f', 0),
            'idle_process_time': Value('f', 0),
            'scan_time': Value('f', 0),
            'log_every': p_log_every
        }
开发者ID:GalakFayyar,项目名称:TabordNG,代码行数:30,代码来源:Swallow.py


示例12: init

def init(confdir="/etc/cslbot"):
    """The bot's main entry point.

    | Initialize the bot and start processing messages.
    """
    multiprocessing.set_start_method('spawn')

    parser = argparse.ArgumentParser()
    parser.add_argument('-d', '--debug', help='Enable debug logging.', action='store_true')
    args = parser.parse_args()
    loglevel = logging.DEBUG if args.debug else logging.INFO
    logging.basicConfig(level=loglevel)

    bot = IrcBot(confdir)

    try:
        bot.start()
    except KeyboardInterrupt:
        # KeyboardInterrupt means someone tried to ^C, so shut down the bot
        bot.disconnect('Bot received a Ctrl-C')
        bot.shutdown_mp()
        sys.exit(0)
    except Exception as ex:
        bot.shutdown_mp(False)
        logging.error("The bot died! %s" % ex)
        output = "".join(traceback.format_exc()).strip()
        for line in output.split('\n'):
            logging.error(line)
        sys.exit(1)
开发者ID:N6UDP,项目名称:cslbot,代码行数:29,代码来源:core.py


示例13: __init__

 def __init__(
     self, loop_debug=False, loop_monitor=True, overlay_dirs=None, debug_level=None,
     log_handler=None, startup_seq_path=None,
 ):
     super().__init__(overlay_dirs)
     self.logger = logger.Logger('middlewared', debug_level).getLogger()
     self.crash_reporting = logger.CrashReporting()
     self.crash_reporting_semaphore = asyncio.Semaphore(value=2)
     self.loop_debug = loop_debug
     self.loop_monitor = loop_monitor
     self.debug_level = debug_level
     self.log_handler = log_handler
     self.startup_seq = 0
     self.startup_seq_path = startup_seq_path
     self.app = None
     self.__loop = None
     self.__thread_id = threading.get_ident()
     # Spawn new processes for ProcessPool instead of forking
     multiprocessing.set_start_method('spawn')
     self.__threadpool = concurrent.futures.ThreadPoolExecutor(
         initializer=lambda: set_thread_name('threadpool_ws'),
         max_workers=10,
     )
     self.__init_procpool()
     self.__wsclients = {}
     self.__events = Events()
     self.__event_sources = {}
     self.__event_subs = defaultdict(list)
     self.__hooks = defaultdict(list)
     self.__server_threads = []
     self.__init_services()
     self.__console_io = False if os.path.exists(self.CONSOLE_ONCE_PATH) else None
     self.jobs = JobsQueue(self)
开发者ID:freenas,项目名称:freenas,代码行数:33,代码来源:main.py


示例14: main

def main():

    global SEM

    if args.forkserver:
        try:
            multiprocessing.set_start_method('forkserver')
        except AttributeError as e:
            # set_start_method is not present in older versions
            print('Not using multiprocessing start_method forkserver')
            print(e)

    if args.pidfile:
        if getpid(args.pidfile) and is_running(getpid(args.pidfile)):
            raise AlreadyRunning('daemon with pidfile {}'.format(args.pidfile))

        with open(args.pidfile, 'w') as fh:
            fh.write(str(os.getpid()))

    SEM = Semaphore(args.nprocs)
    pid = os.getpid()

    def graceful_exit(*_):
        # for some reason the child processes will also execute this function
        # so check that I am actually the parent before executing all of this
        if os.getpid() == pid:
            log.info('\nterminating {} processes'.format(len(PROCESSES)))
            for p in PROCESSES.values():
                p.terminate()
        sys.exit()

    signal.signal(signal.SIGINT, graceful_exit)
    signal.signal(signal.SIGTERM, graceful_exit)
    daemon()
开发者ID:CrowdProcess,项目名称:tqueue,代码行数:34,代码来源:daemon.py


示例15: wrapper

 def wrapper(*args, **kwargs):
     if sys.version_info > (3, 4) and os.name != 'nt':
         mp.set_start_method('spawn', force=True)
         out = func(*args, **kwargs)
         mp.set_start_method('fork', force=True)
     else:
         out = func(*args, **kwargs)
     return out
开发者ID:ZhangXinNan,项目名称:keras,代码行数:8,代码来源:test_multiprocessing.py


示例16: setUpClass

    def setUpClass(cls):
        import multiprocessing as mp
        try:
            mp.set_start_method("spawn")
        except RuntimeError:
            pass
        assert mp.get_start_method() == "spawn"

        write_settings()
        cls.app = QApplication([cls.__name__])
开发者ID:jopohl,项目名称:urh,代码行数:10,代码来源:QtTestCase.py


示例17: main

def main():
    set_start_method('forkserver')
    root = tk.Tk()
    app = GuiApplication(root, title='Crate Cactus')
    app.pack(side='top', fill='both', expand=True)
    try:
        root.mainloop()
    except KeyboardInterrupt:
        root.quit()
        root.destroy()
开发者ID:maoge,项目名称:crate-cactus,代码行数:10,代码来源:gui.py


示例18: see_bin_data

def see_bin_data():
    import multiprocessing as mp
    mp.set_start_method('spawn')
    
    for i in range(10):
        p = mp.Process(target = bin_list)
        p.start()
        p.join()
        
    for i in range(10):
        p = mp.Process(target = bin_dict)
        p.start()
        p.join()
开发者ID:pombreda,项目名称:jobmanager,代码行数:13,代码来源:test_servers.py


示例19: runController

    def runController(self):

        from light_controller import PiLights

        class MyPiLightsManager(BaseManager): pass

        mp.set_start_method('spawn')
       
        MyPiLightsManager.register('PiLights', PiLights)
        manager = MyPiLightsManager()
        manager.start()

        self.piLights = manager.PiLights()
        process = mp.Process(target=mainLoop, args=(piClass,), name="PiLights")
开发者ID:TukwilaFurries,项目名称:HomeAutomation,代码行数:14,代码来源:module_control_block.py


示例20: main

def main(args):
    import multiprocessing
    global _FORK_METHOD_SET

    if not _FORK_METHOD_SET:
        try:
            multiprocessing.set_start_method("fork")
            _FORK_METHOD_SET = True
        except RuntimeError as ex:
            log.warning("multiprocessing.set_start_method: " + str(ex))

    if not hasattr(args, "command_func") or not args.command_func:
        # No command was given.
        args.app.arg_parser.print_help()
        return 1

    # In the case fileConfig undid the command line, which has precedence.
    args.applyLoggingOpts(args.log_levels, args.log_files)

    if args.db_url:
        args.config.set(MAIN_SECT, SA_KEY, args.db_url)
        # Don't want commands and such to use this, so reset.
        args.db_url = None
    elif "MISHMASH_DBURL" in os.environ:
        log.verbose("Using environment MISHMASH_DBURL over configuration: {}"
                    .format(os.environ["MISHMASH_DBURL"]))
        args.config.set(MAIN_SECT, SA_KEY, os.environ["MISHMASH_DBURL"])

    # Run command
    try:
        retval = args.command_func(args, args.config) or 0
    except (KeyboardInterrupt, PromptExit):
        # PromptExit raised when CTRL+D during prompt, or prompts disabled
        retval = 0
    except (sql_exceptions.ArgumentError,):
        _pErr("Database error")
        retval = 1
    except (sql_exceptions.OperationalError,) as db_err:
        print(str(db_err), file=sys.stderr)
        retval = 1
    except CommandError as cmd_err:
        print(str(cmd_err), file=sys.stderr)
        retval = cmd_err.exit_status
    except Exception as ex:
        log.exception(ex)
        _pErr("General error")
        retval = 2

    return retval
开发者ID:nicfit,项目名称:mishmash,代码行数:49,代码来源:__main__.py



注:本文中的multiprocessing.set_start_method函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python multiprocessing.Array类代码示例发布时间:2022-05-27
下一篇:
Python multiprocessing.log_to_stderr函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap