当前位置: 首页>>代码示例>>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;未经允许,请勿转载。