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


Python multiprocessing.TimeoutError方法代碼示例

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


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

示例1: get

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def get(self, timeout=None):
        """
        Return the result when it arrives. If timeout is not None and the
        result does not arrive within timeout seconds then
        multiprocessing.TimeoutError is raised. If the remote call raised an
        exception then that exception will be reraised by get().
        """

        try:
            res = self._q.get(timeout=timeout)
        except queue.Empty:
            raise multiprocessing.TimeoutError("Timed out")

        if isinstance(res, Exception):
            raise res
        return res 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:18,代碼來源:thread_pool.py

示例2: wait_for_device

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def wait_for_device():
    """
    Wait for device to boot. 1 minute timeout.
    """

    wait_for_device_cmd = 'wait-for-device shell getprop sys.boot_completed'
    p = ADB.exec_cmd(wait_for_device_cmd, stdout=subprocess.PIPE)
    boot_completed = p.stdout.readline().strip('\r\n')

    try:
        with Timeout(seconds=60):
            while boot_completed != '1':
                time.sleep(1)
                p = ADB.exec_cmd(wait_for_device_cmd, stdout=subprocess.PIPE)
                boot_completed = p.stdout.readline().strip('\r\n')
                Logger.debug('Waiting for device to finish booting (adb shell getprop sys.boot_completed)')
    except TimeoutError:
        Logger.debug('Timed out while waiting for sys.boot_completed, there might not be a default launcher set, trying to run anyway')
        pass 
開發者ID:MagnetoTesting,項目名稱:magneto,代碼行數:21,代碼來源:__init__.py

示例3: kill

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def kill(self, retries=3, pause=.1):
        try:
            try:
                self.task.get(1)
                self.__set_info('KILLED', "None")
            except (AttributeError, TimeoutError):
                self.__set_info('CANCELLED', "None")
            except UnicodeEncodeError:
                self.__set_info('CRASHED', "None")
            for pid in self.pids:
                try:
                    with open(pid) as f:
                        os.kill(int(f.read().strip()), signal.SIGTERM)
                    os.remove(pid)
                except (IOError, OSError):
                    pass  # simply fail silently when no PID or OS cannot kill it as it is already terminated
            if self.command.__name__.lstrip('_') == 'run' and retries > 0:
                time.sleep(pause)  # wait ... sec that the next call from the command starts
                                   # this is necessary e.g. with cooja command (when Cooja starts a first time for
                                   #  a simulation without a malicious mote then a second time with)
                self.kill(retries - 1, 2 * pause)  # then kill it
        except KeyboardInterrupt:
            self.kill(0, 0) 
開發者ID:dhondta,項目名稱:rpl-attacks,代碼行數:25,代碼來源:behaviors.py

示例4: map

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def map(self, func, iterable, chunksize=None):
        """
        Equivalent of `map()` built-in, without swallowing
        `KeyboardInterrupt`.

        :param func:
            The function to apply to the items.

        :param iterable:
            An iterable of items that will have `func` applied to them.

        """
        # The key magic is that we must call r.get() with a timeout, because
        # a Condition.wait() without a timeout swallows KeyboardInterrupts.
        r = self.map_async(func, iterable, chunksize)

        while True:
            try:
                return r.get(self.wait_timeout)
            except multiprocessing.TimeoutError:
                pass
            except KeyboardInterrupt:
                self.terminate()
                self.join()
                raise 
開發者ID:rodluger,項目名稱:everest,代碼行數:27,代碼來源:pool.py

示例5: get

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def get(self, timeout=None):
        self.wait(timeout)
        if self._result_thread.is_alive():
            raise TimeoutError

        results = []
        for batch in self._result_thread.results():
            for result in batch:
                if isinstance(result, PoolTaskError):
                    raise result.underlying
                elif isinstance(result, Exception):
                    raise result
            results.extend(batch)

        if self._single_result:
            return results[0]

        return results 
開發者ID:ray-project,項目名稱:ray,代碼行數:20,代碼來源:pool.py

示例6: wait_for_image

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def wait_for_image(self, ctx: commands.Context) -> discord.Message:
        await ctx.send(_("Upload an image for me to use! Type `exit` to cancel."))
        msg = None
        while msg is None:

            def check(m):
                return m.author == ctx.author and (m.attachments or "exit" in m.content)

            try:
                msg = await self.bot.wait_for("message", check=check, timeout=60)
            except asyncio.TimeoutError:
                await ctx.send(_("Image adding timed out."))
                break
            if "exit" in msg.content.lower():
                await ctx.send(_("Image adding cancelled."))
                break
        return msg 
開發者ID:TrustyJAID,項目名稱:Trusty-cogs,代碼行數:19,代碼來源:triggerhandler.py

示例7: wait_for_multiple_responses

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def wait_for_multiple_responses(self, ctx: commands.Context) -> List[discord.Message]:
        msg_text = _(
            "Please enter your desired phrase to be used for this trigger."
            "Type `exit` to stop adding responses."
        )
        await ctx.send(msg_text)
        responses: list = []
        while True:

            def check(m):
                return m.author == ctx.author

            try:
                message = await self.bot.wait_for("message", check=check, timeout=60)
                await message.add_reaction("✅")
            except asyncio.TimeoutError:
                return responses
            if message.content == "exit":
                return responses
            else:
                responses.append(message.content) 
開發者ID:TrustyJAID,項目名稱:Trusty-cogs,代碼行數:23,代碼來源:triggerhandler.py

示例8: get

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def get(self, timeout=None):
        """
        Return the result when it arrives. If timeout is not None and the
        result does not arrive within timeout seconds then
        multiprocessing.TimeoutError is raised. If the remote call raised an
        exception then that exception will be reraised by get().
        """

        try:
            res = self._q.get(timeout=timeout)
        except Queue.Empty:
            raise multiprocessing.TimeoutError("Timed out")

        if isinstance(res, Exception):
            raise res
        return res 
開發者ID:splunk,項目名稱:SA-ctf_scoreboard,代碼行數:18,代碼來源:thread_pool.py

示例9: map

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def map(self, func, items, chunksize=None):
        """
        A replacement for :func:`map` that handles :exc:`KeyboardInterrupt`.

        :param func:
            Function to apply to the items.

        :param items:
            Iterable of items to have `func` applied to.
        """
        # Call r.get() with a timeout, since a Condition.wait() swallows
        # KeyboardInterrupts without a timeout
        r = self.map_async(func, items, chunksize)

        while True:
            try:
                return r.get(self._wait_timeout)
            except TimeoutError:
                pass
            except KeyboardInterrupt:
                self.terminate()
                self.join()
                raise 
開發者ID:bfarr,項目名稱:kombine,代碼行數:25,代碼來源:interruptible_pool.py

示例10: map

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def map(self, func, items, chunksize=None):
        """ Catch keyboard interuppts to allow the pool to exit cleanly.

        Parameters
        ----------
        func: function
            Function to call
        items: list of tuples
            Arguments to pass
        chunksize: int, Optional
            Number of calls for each process to handle at once
        """
        results = self.map_async(func, items, chunksize)
        while True:
            try:
                return results.get(1800)
            except TimeoutError:
                pass
            except KeyboardInterrupt:
                self.terminate()
                self.join()
                raise KeyboardInterrupt 
開發者ID:gwastro,項目名稱:pycbc,代碼行數:24,代碼來源:pool.py

示例11: abortable_worker

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def abortable_worker(func, *args, **kwargs):
    # returns ("MULTIPROCESSING_TIMEOUT",) if timeout
    timeout = kwargs['timeout']
    p = multiprocessing.dummy.Pool(1)
    res = p.apply_async(func, args=args)
    # assumes timeout is an integer >= 1
    for i in range(timeout + 1):
        if i > 0:
            time.sleep(1)
        if res.ready():
            if res.successful():
                try:
                    return res.get(timeout=1)
                except multiprocessing.TimeoutError:
                    logger.info("Aborting due to timeout in get")
                    p.terminate()
                    return (TIMEOUT_ID,)
    logger.info("Aborting due to timeout")
    p.terminate()
    return (TIMEOUT_ID,) 
開發者ID:kastnerkyle,項目名稱:representation_mixing,代碼行數:22,代碼來源:loaders.py

示例12: join_proc

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def join_proc(self):
		self.log.info("Requesting job-dispatching RPC system to halt.")
		self.run_flag.value = 0

		# We have to consume any remaining jobs in the output queue, or we'll never
		# fully exit.
		if self.main_job_agg:
			for _ in range(60 * 5):
				try:
					self.main_job_agg.join(timeout=1)
					return

				except multiprocessing.TimeoutError:
					pass

				self.log.info("Waiting for job dispatcher to join. Currently active jobs in queue: %s",
						self.normal_out_queue.qsize()
					)

			while True:
				self.main_job_agg.join(timeout=1)
				try:
					self.main_job_agg.join(timeout=1)
					return

				except multiprocessing.TimeoutError:
					pass

				self.log.error("Timeout when waiting for join. Bulk consuming from intermediate queue.")
				try:
					while 1:
						self.normal_out_queue.get_nowait()
				except queue.Empty:
					pass 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:36,代碼來源:JobDispatcher.py

示例13: join_aggregator

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def join_aggregator(self):

		self.log.info("Asking Aggregator process to stop.")
		runStatus.agg_run_state.value = 0
		if hasattr(self, 'main_job_agg'):
			while 1:
				try:
					self.main_job_agg.join(timeout=1)
					break
				except multiprocessing.TimeoutError:
					print("Failed to join main_job_agg")

		self.log.info("Aggregator joined.") 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:15,代碼來源:RunManager.py

示例14: scrape_with_timeout

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def scrape_with_timeout(page):
    pool = NDPool(processes=1)
    async_result = pool.apply_async(scrape_page, (page,))
    result = None
    try:
        result = async_result.get(timeout=600)
        pool.close()
    except TimeoutError:
        logger.info(u'page scrape timed out: {}'.format(page))
        pool.terminate()

    pool.join()
    return result 
開發者ID:ourresearch,項目名稱:oadoi,代碼行數:15,代碼來源:queue_green_oa_scrape.py

示例15: test_map_chunksize

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import TimeoutError [as 別名]
def test_map_chunksize(self):
        try:
            self.pool.map_async(sqr, [], chunksize=1).get(timeout=TIMEOUT1)
        except multiprocessing.TimeoutError:
            self.fail("pool.map_async with chunksize stalled on null list") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_multiprocessing.py


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