当前位置: 首页>>代码示例>>Python>>正文


Python threading.ThreadError方法代码示例

本文整理汇总了Python中threading.ThreadError方法的典型用法代码示例。如果您正苦于以下问题:Python threading.ThreadError方法的具体用法?Python threading.ThreadError怎么用?Python threading.ThreadError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在threading的用法示例。


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

示例1: _get_my_tid

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def _get_my_tid(self):
        """determines this (self's) thread id"""
        if not self.isAlive():
            raise threading.ThreadError("the thread is not active")

        # do we have it cached?
        if hasattr(self, "_thread_id"):
            return self._thread_id

        # no, look for it in the _active dict
        for tid, tobj in threading._active.items():
            if tobj is self:
                self._thread_id = tid
                return tid

        raise AssertionError("could not determine the thread's id") 
开发者ID:fitoprincipe,项目名称:ipygee,代码行数:18,代码来源:threading.py

示例2: _try_acquire

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def _try_acquire(self, blocking, watch):
        try:
            self.trylock()
        except IOError as e:
            if e.errno in (errno.EACCES, errno.EAGAIN):
                if not blocking or watch.expired():
                    return False
                else:
                    raise _utils.RetryAgain()
            else:
                raise threading.ThreadError("Unable to acquire lock on"
                                            " `%(path)s` due to"
                                            " %(exception)s" %
                                            {
                                                'path': self.path,
                                                'exception': e,
                                            })
        else:
            return True 
开发者ID:harlowja,项目名称:fasteners,代码行数:21,代码来源:process_lock.py

示例3: release

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def release(self):
        """Release the previously acquired lock."""
        if not self.acquired:
            raise threading.ThreadError("Unable to release an unacquired"
                                        " lock")
        try:
            self.unlock()
        except IOError:
            self.logger.exception("Could not unlock the acquired lock opened"
                                  " on `%s`", self.path)
        else:
            self.acquired = False
            try:
                self._do_close()
            except IOError:
                self.logger.exception("Could not close the file handle"
                                      " opened on `%s`", self.path)
            else:
                self.logger.log(_utils.BLATHER,
                                "Unlocked and closed file lock open on"
                                " `%s`", self.path) 
开发者ID:harlowja,项目名称:fasteners,代码行数:23,代码来源:process_lock.py

示例4: kill

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def kill(self, force_and_wait=False):
        pass
    #     try:
    #         self._raiseExc(KillThreadException)

    #         if force_and_wait:
    #             time.sleep(0.1)
    #             while self.isAlive():
    #                 self._raiseExc(KillThreadException)
    #                 time.sleep(0.1)
    #     except threading.ThreadError:
    #         pass

    # def onKilled(self):
    #     pass

    # def run(self):
    #     try:
    #         self._Thread__target(*self._Thread__args, **self._Thread__kwargs)
    #     except KillThreadException:
    #         self.onKilled() 
开发者ID:plexinc,项目名称:plex-for-kodi,代码行数:23,代码来源:threadutils.py

示例5: _get_my_tid

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def _get_my_tid(self):
		"""determines this (self's) thread id"""
		if not self.isAlive():
			raise threading.ThreadError("the thread is not active")

		# do we have it cached?
		if hasattr(self, "_thread_id"):
			return self._thread_id

		# no, look for it in the _active dict
		for tid, tobj in threading._active.items():
			if tobj is self:
				self._thread_id = tid
				return tid

		raise AssertionError("could not determine the thread's id") 
开发者ID:turingsec,项目名称:marsnake,代码行数:18,代码来源:threads.py

示例6: active

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def active(self):
        """
        重载感知器生效函数,加入自动刷新线程的生效操作。

        :return: 无返回
        :rtype: None
        :raises ThreadError: 创建线程失败
        """
        super(CronSensor, self).active()
        try:
            self._reload_thread = threading.Thread(
                target=self._reload)
            self._reload_thread.daemon = True
            self._reload_thread.start()
        except threading.ThreadError as e:
            log.r(e, "create new thread err") 
开发者ID:baidu,项目名称:ARK,代码行数:18,代码来源:cron_sensor.py

示例7: _get_my_tid

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def _get_my_tid(self):
		"""determines this (self's) thread id"""
		if not self.isAlive():
			raise threading.ThreadError("the thread is not active")
		
		# do we have it cached?
		if hasattr(self, "_thread_id"):
			return self._thread_id
		
		# no, look for it in the _active dict
		for tid, tobj in threading._active.items():
			if tobj is self:
				self._thread_id = tid
				return tid
		
		raise AssertionError("could not determine the thread's id") 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:18,代码来源:PupyJob.py

示例8: start

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def start(self):
        assert self._job.pending
        # create the listener thread to handle incoming requests
        listener = threading.Thread(
            target=self.listener,
            args=(self._socket, self._job, self._workers),
            kwargs={"shutdown_delay": self.SHUTDOWN_DELAY})
        # launch listener thread and handle thread errors
        for retry in reversed(range(10)):
            try:
                listener.start()
            except threading.ThreadError:
                # thread errors can be due to low system resources while fuzzing
                LOG.warning("ThreadError (listener), threads: %d", threading.active_count())
                if retry < 1:
                    raise
                time.sleep(1)
                continue
            self._listener = listener
            break 
开发者ID:MozillaSecurity,项目名称:grizzly,代码行数:22,代码来源:sapphire_load_manager.py

示例9: test_sapphire_worker_03

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def test_sapphire_worker_03(mocker):
    """test SapphireWorker.launch() fail cases"""
    serv_con = mocker.Mock(spec=socket.socket)
    serv_job = mocker.Mock(spec=SapphireJob)
    fake_thread = mocker.patch("sapphire.sapphire_worker.threading.Thread", autospec=True)
    mocker.patch("sapphire.sapphire_worker.time.sleep", autospec=True)

    serv_con.accept.side_effect = socket.timeout
    assert SapphireWorker.launch(serv_con, serv_job) is None

    serv_con.accept.side_effect = None
    conn = mocker.Mock(spec=socket.socket)
    serv_con.accept.return_value = (conn, None)
    fake_thread.side_effect = threading.ThreadError
    assert SapphireWorker.launch(serv_con, serv_job) is None
    assert conn.close.call_count == 1
    assert serv_job.accepting.clear.call_count == 0
    assert serv_job.accepting.set.call_count == 1 
开发者ID:MozillaSecurity,项目名称:grizzly,代码行数:20,代码来源:test_sapphire_worker.py

示例10: launch

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def launch(cls, listen_sock, job):
        assert job.accepting.is_set()
        conn = None
        try:
            conn, _ = listen_sock.accept()
            conn.settimeout(None)
            # create a worker thread to handle client request
            w_thread = threading.Thread(target=cls.handle_request, args=(conn, job))
            job.accepting.clear()
            w_thread.start()
            return cls(conn, w_thread)
        except (socket.error, socket.timeout):
            if conn is not None:  # pragma: no cover
                conn.close()
        except threading.ThreadError:
            if conn is not None:  # pragma: no cover
                conn.close()
            # reset accepting status
            job.accepting.set()
            LOG.warning("ThreadError (worker), threads: %d", threading.active_count())
            # wait for system resources to free up
            time.sleep(0.1)
        return None 
开发者ID:MozillaSecurity,项目名称:grizzly,代码行数:25,代码来源:sapphire_worker.py

示例11: abortall

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def abortall():
    for p in Cache.publishers:
        try:
            p.abort()
        except threading.ThreadError as e:
            log(msg=_('Error aborting: %s - Error: %s') % (str(p), str(e)))
    Cache.dispatcher.abort()
    for p in Cache.publishers:
        p.join(0.5)
    Cache.dispatcher.join(0.5)
    if len(threading.enumerate()) > 1:
        main_thread = threading.current_thread()
        log(msg=_('Enumerating threads to kill others than main (%i)') % main_thread.ident)
        for t in threading.enumerate():
            if t is not main_thread and t.is_alive():
                log(msg=_('Attempting to kill thread: %i: %s') % (t.ident, t.name))
                try:
                    t.abort(0.5)
                except (threading.ThreadError, AttributeError):
                    log(msg=_('Error killing thread'))
                else:
                    if not t.is_alive():
                        log(msg=_('Thread killed succesfully'))
                    else:
                        log(msg=_('Error killing thread')) 
开发者ID:KenV99,项目名称:script.service.kodi.callbacks,代码行数:27,代码来源:default.py

示例12: close

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def close(self):
        """
        Destructor for this audio interface. Waits the threads to finish their
        streams, if desired.
        """
        with self.halting:  # Avoid simultaneous "close" threads

            if not self.finished:  # Ignore all "close" calls, but the first,
                self.finished = True  # and any call to play would raise ThreadError

                # Closes all playing AudioThread instances
                while True:
                    with self.lock:  # Ensure there's no other thread messing around
                        try:
                            thread = self._threads[0]  # Needless to say: pop = deadlock
                        except IndexError:  # Empty list
                            break  # No more threads

                    thread.stop()
                    thread.join()

                # Finishes
                assert not self._pa._streams  # No stream should survive
                self._pa.terminate() 
开发者ID:TUT-ARG,项目名称:sed_vis,代码行数:26,代码来源:audio_player.py

示例13: play

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def play(self, offset=0.0, duration=None):
        """
        Start another thread playing the given audio sample iterable (e.g. a
        list, a generator, a NumPy np.ndarray with samples), and play it.
        The arguments are used to customize behaviour of the new thread, as
        parameters directly sent to PyAudio's new stream opening method, see
        AudioThread.__init__ for more.
        """
        if self.playing:
            # If playback is on, stop play
            self.stop()

        with self.lock:
            if self.finished:
                raise threading.ThreadError("Trying to play an audio stream while "
                                            "halting the AudioIO manager object")
            self.player_thread = AudioThread(device_manager=self,
                                             audio=self.get_segment(offset, duration),
                                             chunk_size=2048,
                                             sampling_rate=self.sampling_rate,
                                             nchannels=self.channels)

            self.player_thread.start()
            self.playing = True 
开发者ID:TUT-ARG,项目名称:sed_vis,代码行数:26,代码来源:audio_player.py

示例14: __enter__

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def __enter__(self):
        self._succ = self._lock.acquire(False)
        if not self._succ:
            raise threading.ThreadError("This DataFlow is not reentrant!") 
开发者ID:tensorpack,项目名称:dataflow,代码行数:6,代码来源:base.py

示例15: _get_my_tid

# 需要导入模块: import threading [as 别名]
# 或者: from threading import ThreadError [as 别名]
def _get_my_tid(self):
        if not self.isAlive():
            raise threading.ThreadError("the thread is not active")

        if hasattr(self, "_thread_id"):
            return self._thread_id

        for tid, tobj in threading._active.items():
            if tobj is self:
                self._thread_id = tid
                return tid

        raise AssertionError("could not determine the thread's id") 
开发者ID:LightTable,项目名称:Python,代码行数:15,代码来源:ltmain.py


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