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

Python multiprocessing.Pipe类代码示例

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

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



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

示例1: test_request_with_fork

    def test_request_with_fork(self):
        try:
            from multiprocessing import Process, Pipe
        except ImportError:
            raise SkipTest("No multiprocessing module")

        coll = self.c.test.test
        coll.remove(safe=True)
        coll.insert({'_id': 1}, safe=True)
        coll.find_one()
        self.assert_pool_size(1)
        self.c.start_request()
        self.assert_pool_size(1)
        coll.find_one()
        self.assert_pool_size(0)
        self.assert_request_with_socket()

        def f(pipe):
            # We can still query server without error
            self.assertEqual({'_id':1}, coll.find_one())

            # Pool has detected that we forked, but resumed the request
            self.assert_request_with_socket()
            self.assert_pool_size(0)
            pipe.send("success")

        parent_conn, child_conn = Pipe()
        p = Process(target=f, args=(child_conn,))
        p.start()
        p.join(1)
        p.terminate()
        child_conn.close()
        self.assertEqual("success", parent_conn.recv())
开发者ID:dampier,项目名称:mongo-python-driver,代码行数:33,代码来源:test_pooling.py


示例2: __init__

class PluginRunner:
  def __init__(self, plugin):
    self.name = plugin
    self.proc = None
    self.running = False
    self.local_pipe, self.remote_pipe = Pipe()

  def getConnection(self):
    return self.local_pipe

  def start(self):
    assert not self.running, "Already running."
    self.running = True
    self.thread = Thread(target=self.run)
    self.thread.start()

  def restart(self):
    self.proc.terminate()

  def stop(self):
    assert self.running, "Running"
    self.running = False
    self.proc.terminate()
    self.thread.join()
    self.remote_pipe.close()
    self.local_pipe.close()

  def run(self):
    while self.running:
      self.proc = Process(target=launch, args=('repeat', self.remote_pipe))
      self.proc.start()
      print("Waiting on proc to end")
      self.proc.join()
开发者ID:hashbang-legacy,项目名称:bot,代码行数:33,代码来源:plugin.py


示例3: ProcessStarter

class ProcessStarter(object):
    
    def __init__(self):
        '''
        Setup the shared memory data structure model and initialize the control parts.
        '''
        self.running = True
        self.orprocess  = None
        self.guiprocess = None
        self.pipeGUI, self.pipeOR = Pipe()
        self.StartProcesses()

    def StartProcesses(self):
        self.guiprocess = Process(target=self.__startGUI__)
        self.guiprocess.start()        
        self.pipeGUI.send(["StartViewer", None])
        self.orprocess = Process(target=ORServer,args=(self.pipeOR,))
        self.orprocess.start()
        return True
    
    def terminate(self):
        try:
            self.pipeGUI.send(["Stop", None])
            self.guiprocess.terminate()
            self.orprocess.terminate()
        except:
            pass

    def __startGUI__(self):
        app  = QtGui.QApplication(sys.argv)
        form = pnpApp(self.pipeGUI, self)
        form.show()
        sys.exit(app.exec_())
开发者ID:rishabh-battulwar,项目名称:human_demos,代码行数:33,代码来源:ProcessStarter.py


示例4: get_resource

def get_resource(url,is_ajax=0,ajax_timeout=2,js_timeout=5,timeout_retry_times=0,jsengine_type=1000): 
	parent_conn,child_conn=Pipe()
	p=Process(target=CrawlerProcess,args=(child_conn,url))
	p.start()
	p.join()
	html=parent_conn.recv()
	return html
开发者ID:extremin,项目名称:pyqt,代码行数:7,代码来源:service_new.py


示例5: resolve_list

def resolve_list(hostname_list, qtype='A', tokens=300, flag=False, servers=[('8.8.8.8', 53)], timeout=(1, 3, 5, 7)):
    parent, child = Pipe()
    p = Process(target=_resolve_list, args=(child, hostname_list, qtype, tokens, flag, servers, timeout))
    p.start()
    result = parent.recv()
    p.join()
    return result
开发者ID:nms84,项目名称:hydra_resolver,代码行数:7,代码来源:hydra_wrapper.py


示例6: fn_with_timeout

        def fn_with_timeout(*args, **kwargs):
            conn1, conn2 = Pipe()
            kwargs["_conn"] = conn2
            th = Process(target=partial(fn, best_loss=self._best_loss), args=args, kwargs=kwargs)
            th.start()
            if conn1.poll(self.trial_timeout):
                fn_rval = conn1.recv()
                th.join()
            else:
                self.info("TERMINATING DUE TO TIMEOUT")
                th.terminate()
                th.join()
                fn_rval = "return", {"status": hyperopt.STATUS_FAIL, "failure": "TimeOut"}

            assert fn_rval[0] in ("raise", "return")
            if fn_rval[0] == "raise":
                raise fn_rval[1]

            # -- remove potentially large objects from the rval
            #    so that the Trials() object below stays small
            #    We can recompute them if necessary, and it's usually
            #    not necessary at all.
            if fn_rval[1]["status"] == hyperopt.STATUS_OK:
                fn_loss = float(fn_rval[1].get("loss"))
                fn_preprocs = fn_rval[1].pop("preprocs")
                fn_classif = fn_rval[1].pop("classifier")
                fn_iters = fn_rval[1].pop("iterations")
                if fn_loss < self._best_loss:
                    self._best_preprocs = fn_preprocs
                    self._best_classif = fn_classif
                    self._best_loss = fn_loss
                    self._best_iters = fn_iters
            return fn_rval[1]
开发者ID:2dpodcast,项目名称:hyperopt-sklearn,代码行数:33,代码来源:estimator.py


示例7: go

def go():
    global graphic_view, status_label
    data_parent, data_child = Pipe(duplex=False)
    receiver = Process(target=generate_data, args=(data_child,))
    receiver.daemon = True
    receiver.start()

    scene = QGraphicsScene()
    graphic_view.setScene(scene)
    scene.setSceneRect(0, 0, 1024, 1024)

    x_pos = 0
    y_pos = 0
    t = time.time()
    while True:
        speed = time.time()
        data = data_parent.recv()
        spectrogram = Spectrogram(data)
        pixmap = QPixmap.fromImage(spectrogram.create_spectrogram_image(transpose=True))

        scene.setSceneRect(scene.sceneRect().adjusted(0, 0, 0, pixmap.height()))
        item = scene.addPixmap(pixmap)
        item.setPos(x_pos, y_pos)
        y_pos += pixmap.height()
        graphic_view.fitInView(scene.sceneRect())
        status_label.setText("Height: {0:.0f} // Speed: {1:.2f}  // Total Time: {2:.2f}".format(scene.sceneRect().height(),
                                                                                                1/(time.time()-speed),
                                                                                                time.time()-t))
        QApplication.instance().processEvents()
开发者ID:jopohl,项目名称:urh,代码行数:29,代码来源:live_spectrogram.py


示例8: take_lock

def take_lock(fd, timeout=None, shared=False):
	'''Take a lock on a file descriptor

	If timeout is 0 the lock is taken without blocking,
	if timeout is None we block indefinitely,
	if timeout is a positive number we time out in that many seconds.

	If shared is True this is a shared lock,
	so can lock with other shared locks,
	if shared is False this is an exclusive lock.

	with open(path, 'r') as lock:
		take_lock(lock.fileno(), timeout, shared)

	'''
	if timeout is None or timeout == 0:
		flags = (LOCK_SH if shared else LOCK_EX)
		flags |= (LOCK_NB if timeout == 0 else 0)
		flock(fd, flags)
		return
	piper, pipew = Pipe(duplex=False)
	p = Process(target=_set_alarm_and_lock,
	            args=(fd, pipew, timeout, shared))
	p.start()
	err = piper.recv()
	p.join()
	if err:
		if isinstance(err, IOError) and err.errno == EINTR:
			raise IOError(EAGAIN, strerror(EAGAIN))
		raise err
开发者ID:fishface60,项目名称:python-flock,代码行数:30,代码来源:__init__.py


示例9: QuickSortMPListArray

def QuickSortMPListArray(A,conn,NumProcs):
        if len(A)<=1 :
                conn.send(A)
                conn.close()
        elif int(NumProcs)<1:
                conn.send(QuickSortListArray(A))
                conn.close()
        else:
                lesser=[]
                greater=[]
                pv=[]
                Pivot=A.pop(0)
                pvVal=int(Pivot[0])
                lesser=[x for x in A if x[0] < pvVal]
                greater=[x for x in A if x[0] > pvVal]
                pv=[x for x in A if x[0] == pvVal]
                pv.append(Pivot)
                Procs=int(NumProcs)-1
                pConnLeft,cConnLeft=Pipe()
                leftProc=Process(target=QuickSortMPListArray,args=(lesser,cConnLeft,Procs))
                pConnRight,cConnRight=Pipe()
                rightProc=Process(target=QuickSortMPListArray,args=(greater,cConnRight,Procs))
                

                leftProc.start()
                rightProc.start()
                conn.send(pConnLeft.recv()+pv+pConnRight.recv())
                conn.close()
        
                leftProc.join()
                rightProc.join()
        return
开发者ID:rob-berkes,项目名称:wikicount,代码行数:32,代码来源:sorting.py


示例10: process_pipe

def process_pipe():
    parent_conn, child_conn = Pipe()
    p = Process(target=pipe_test, args=(child_conn,))
    p.start()
    print parent_conn.recv()
    p.join()
    parent_conn.close()
开发者ID:jianwei1216,项目名称:my-scripts,代码行数:7,代码来源:process.py


示例11: main

def main():
    startup_checks()
    parser = argparse.ArgumentParser()
    parser.add_argument("repourl", nargs="?", default=REPOURL, help="URL of "
                        "repository to crawl")
    arguments = parser.parse_args(sys.argv[1:])

    parent_conn, child_conn = Pipe()
    crawler = Process(target=crawl, args=(arguments.repourl, child_conn))
    crawler.start()
    while True:
        package_url = parent_conn.recv()
        if package_url is None:
            break
        print "Processing %s" % package_url
        tempdir = tempfile.mkdtemp()
        p_obj = Package(package_url, tempdir)
        database = pymongo.Connection("localhost", 27017).symdex
        collection = database.libraries
        for key, value in p_obj.libs_and_syms.items():
            mongo_dict = {"package": os.path.basename(package_url),
                          "library": key, "symbols": value}
            collection.insert(mongo_dict)
        shutil.rmtree(tempdir)
        os.remove(package_url)
    crawler.join()
开发者ID:chsigi,项目名称:symdex,代码行数:26,代码来源:symdex_worker.py


示例12: transcode

 def transcode(self, path, format='mp3', bitrate=False):
     if self.stopping.is_set():
         return
     try:
         stop = Event()
         start_time = time.time()
         parent_conn, child_conn = Pipe()
         process = Process(target=transcode_process,
                 args=(child_conn, path, stop, format, bitrate))
         process.start()
         while not (self.stopping.is_set() or stop.is_set()):
             data = parent_conn.recv()
             if not data:
                 break
             yield data
         logger.debug("Transcoded %s in %0.2f seconds." % (path.encode(cfg['ENCODING']), time.time() - start_time))
     except GeneratorExit:
         stop.set()
         logger.debug("User canceled the request during transcoding.")
     except:
         stop.set()
         logger.warn("Some type of error occured during transcoding.")
     finally:
         parent_conn.close()
         process.join()
开发者ID:daveisadork,项目名称:Blofeld,代码行数:25,代码来源:transcode.py


示例13: __init__

class StubExecuteTestsFunc:
    def __init__(self):
        self.main_conn, self.func_conn = Pipe()
        self._called = self._complete = None
        self.stub_reset()

    def stub_reset(self):
        self._called = self._complete = False

    def stub_complete(self):
        self._complete = True
        self.main_conn.send(StubExecuteTestsFuncConnMessages.COMPLETE)

    def stub_called(self):
        if not self._called and self.main_conn.poll():
            conn_message = self.main_conn.recv()
            if conn_message == StubExecuteTestsFuncConnMessages.CALLED:
                self._called = True
        return self._called

    def __enter__(self):
        self.stub_reset()
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.stub_complete()

    def __call__(self, *_):
        self._called = True
        self.func_conn.send(StubExecuteTestsFuncConnMessages.CALLED)
        while not self._complete:
            conn_message = self.func_conn.recv()
            if conn_message == StubExecuteTestsFuncConnMessages.COMPLETE:
                self._complete = True
开发者ID:janhavideshpande,项目名称:sis-qa-test-auto,代码行数:34,代码来源:test_executor.py


示例14: run

    def run(self):
        logging.info('Visualizer thread started')

        parent_end, child_end = Pipe()

        # Sensible default value for max_process
        max_process = 2
        process_count = 0

        while not self.stop or not self.job_backlog.empty():
            while parent_end.poll(0.1):
                parent_end.recv() ## currently not using the info... irrelevant
                
                ## TODO - a signal to notify the viewer that visuzaliztion job has been finished... 
                #self.controller.view_update(self)
                process_count -= 1

            if self.job_backlog.empty():
                time.sleep(1)
            elif process_count < max_process:
                process_count += 1
                run_name, function, snapshot = self.job_backlog.get_nowait()
                if not (run_name in self.remove_run_name):
                    logging.info('Added job to visuzalizer Que: ' + str(run_name))
                    logging.info('No. of jobs in Que: ' + str(process_count))
                    p = Process(target=self.render_graph,
                                args=(function, snapshot, run_name, child_end))
                    p.start()
                
        logging.info('Visualizer Finished')
开发者ID:maciejkurek87,项目名称:ARDEGO,代码行数:30,代码来源:visualizer.py


示例15: main

def main():
    logging.basicConfig(level=logging.INFO)

    args = parse_args()
    print args

    echo_server = Process(target=EchoServer('ipc://ECHO:1',
            args.echo_delay).run)
    client = Process(target=JsonClient('ipc://PRODUCER_REP:1',
                                       'ipc://PRODUCER_PUB:1',
                                       args.request_count,
                                       request_delay=args.request_delay).run)
    parent_pipe, child_pipe = Pipe(duplex=True)
    async_server_adapter = Process(
        target=AsyncJsonServerAdapter('ipc://ECHO:1', 'ipc://PRODUCER_REP:1',
                                      'ipc://PRODUCER_PUB:1', child_pipe).run
    )

    try:
        echo_server.start()
        async_server_adapter.start()
        client.start()
        client.join()
        parent_pipe.send('close')
        async_server_adapter.join()
    except KeyboardInterrupt:
        pass
    client.terminate()
    async_server_adapter.terminate()
    echo_server.terminate()
    # Since ipc:// creates files, delete them on exit
    cleanup_ipc_uris(('ipc://ECHO:1', 'ipc://PRODUCER_REP:1',
            'ipc://PRODUCER_PUB:1'))
开发者ID:cfobel,项目名称:zmq_helpers,代码行数:33,代码来源:test_consumer.py


示例16: train

    def train(self):
        conf = self.conf
        if len(self.training_set) == 0:
            return True
        try:
            # Scale inputs and particles?
            self.input_scaler = preprocessing.StandardScaler().fit(self.training_set)
            scaled_training_set = self.input_scaler.transform(self.training_set)

            # Scale training data
            self.output_scaler = preprocessing.StandardScaler(with_std=False).fit(self.training_fitness)
            adjusted_training_fitness = self.output_scaler.transform(self.training_fitness)
            gp = self.regressor_countructor()
            # Start a new process to fit the data to the gp, because gp.fit is
            # not thread-safe
            parent_end, child_end = Pipe()

            self.controller.acquire_training_sema()
            logging.info("Training regressor")
            p = Process(target=self.fit_data, args=(gp, scaled_training_set, adjusted_training_fitness, child_end))
            p.start()
            self.regr = parent_end.recv()
            if self.regr is None:
                raise Exception("Something went wrong with the regressor")
            else:
                logging.info("Regressor training successful")
                self.controller.release_training_sema()
                self.gp = gp
                return True
        except Exception, e:
            logging.info("Regressor training failed.. retraining.. " + str(e))
            return False
开发者ID:maciejkurek87,项目名称:ARDEGO,代码行数:32,代码来源:regressors.py


示例17: Airplay

class Airplay():
	def __init__(self, file):
		self.metadata   = AIRPLAY_DEFAULT
		self.block      = ''
		self.out_pipe, self.in_pipe = Pipe()

		p = Process(target=read_shairport_pipe, args=(file, self.in_pipe,))
		p.start()

	def __repr__(self):
		printout = "metadata:\n"+self.metadata
		# for k,v in self.metadata.items():
		# 		printout += '%12s : %s\n' % (k,v)
		return printout


	def grab(self):
		if self.out_pipe.poll(0):
			s = True
			self.metadata = self.out_pipe.recv()   # prints "[42, None, 'hello']"
		else:
			print "nothing in pipe"
			s = False

		return s
开发者ID:baloothebear4,项目名称:VolumioDisplay,代码行数:25,代码来源:readmd2.py


示例18: run_http_server

def run_http_server(redirect_uri = None, modify_port = True, port_range = (10000, 10010) ):
    """Returns (modified) redirect_uri"""
    from multiprocessing import Process, Pipe
    from urllib.parse import urlsplit, urlunsplit
    if redirect_uri is None:
        redirect_uri = "http://localhost"
    p = urlsplit(redirect_uri)
    #Ensure hostname is localhost or 127.0.0.1
    if p.hostname != "127.0.0.1" and p.hostname != "localhost":
        raise ValueError("url must have host of 127.0.0.1 or localhost! Got: {}".format(p.hostname))
    if not modify_port:
        if p.port is not None:
            port_range = (int(p.port), int(p.port))
        else:
            port_range = (int(80), int(80))
    parent_port_pipe, child_port_pipe = Pipe()
    parent_pipe, child_pipe = Pipe()
    httpd_p = Process(target = _run_http_server, args = (child_port_pipe, child_pipe, port_range))
    httpd_p.start()
    if parent_port_pipe.poll(3000):
        final_port = parent_port_pipe.recv()
    else:
        raise Exception("Timeout waiting for HTTP server process to start")
    if final_port == 0:
        #Could not find a port
        raise Exception("Could not find open port")
    netloc = "{0}:{1}".format(p.hostname, final_port)
    if p.path:
        path = p.path
    else:
        path = '/'
    p = p._replace(netloc = netloc, path = path)
    return (urlunsplit(p), parent_pipe, httpd_p)
开发者ID:pyokagan,项目名称:pyoauth2client,代码行数:33,代码来源:ui.py


示例19: recog_proc

    def recog_proc(self, child_recog: Pipe, e_recog: Event, yolo_type: str):
        """
        Parallel process for object recognition

        Arguments:
            child_recog {Pipe} -- pipe for communication with parent process,
                sends bbox yolo type of recognized object
            e_recog {Event} -- event for indicating complete recognize in frame
        """

        # initialize YOLO
        yolo = Yolo(yolo_type)
        e_recog.set()
        print("yolo defined")

        while True:
            frame = child_recog.recv()
            print("recog process frame recieved")
            if frame is None:
                print("FRAME NONE? R U SURE ABOUT THAT?!")
                return
            res = yolo.detect(frame, cvmat=True)
            print("recog send")
            e_recog.set()
            child_recog.send(res)
开发者ID:DiggiDon,项目名称:Tracking_system,代码行数:25,代码来源:track_system.py


示例20: run

class ProcessHandler:
    '''
    run(): The run() method is the entry point for a thread.
    start(): The start() method starts a thread by calling the run method.
    join([time]): The join() waits for threads to terminate.
    isAlive(): The isAlive() method checks whether a thread is still executing.
    '''

    def __init__(self, daemonic, pipe):
        self.daemonic = daemonic
        self.pipe = pipe
        if self.pipe:
            self.parent_conn, self.child_conn = Pipe(duplex=False)

    @abc.abstractmethod
    def run(self, *args):
        pass

    def start(self, *args):
        # Close write fd because parent not going to write
        if not self.pipe:
            self.process = Process(target=self.run, args=args)
        else:
            self.process = Process(
                target=self.run, args=(self.child_conn,) + args)
        if self.daemonic:
            self.process.daemon = True
        self.process.start()

    def join(self):
        if self.pipe:
            self.parent_conn.close()
            self.child_conn.close()
        self.process.join()
    """
开发者ID:albarralnunez,项目名称:python_concurrency,代码行数:35,代码来源:process_handler.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python multiprocessing.Pool类代码示例发布时间:2022-05-27
下一篇:
Python multiprocessing.Manager类代码示例发布时间: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