我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用threading.Thread.start()。
def run(self): self.log(' TaskThread : running ...', prefixname = True) while True: # If there's not pending task, wait to avoid busy-looping. if len(self.tasks) == 0: self.wati_for_task.wait() # If stop() is called, remaining tasks won't be exectued ! if self.wati_for_stop.isSet(): break # Remove a pending task from the queue. self.__qlock.acquire() task = self.tasks.pop(0) self.__qlock.release() if task: self.debug_log(' TaskThread : start executing ... task (%d)'%(task.taskid), prefixname = True) task.run() self.log(' TaskThread : ending.', prefixname = True)
def testMTRandomness(self): q = queue.Queue() def proc(): rng = tar.gen_rng() with tar.with_rng(rng): time.sleep(0.5) state = tar.get_rng().get_state() time.sleep(0.5) q.put(state) threads = [Thread(target=proc) for i in range(2)] map_exec(Thread.start, threads) map_exec(Thread.join, threads) v1, v2 = q.get(), q.get() self.assertFalse(np.allclose(v1[1], v2[1]))
def __init__(self): Thread.__init__(self) #send start message #jandi payload = { "body" : self.channel + " start", "connectColor" : "#FAC11B", "connectInfo" : [{ "title" : self.channel, "description" : self.channel + " start" }] } result = requests.post(self.jandi_url, data=json.dumps(payload), headers=self.jandi_header) #slack / insert your slack address #self.slack = Slacker('') #self.slack.chat.post_message(self.channel, 'start')
def addPeriodicAction(self, start, period, task, name): """Add a task to be run periodically. Adds an action to be run at a specific initial time, and every period thereafter. The scheduler will not reschedule a task until the last scheduled instance of the task has completed. If a task with the given name is already registered with the scheduler, that task will be removed from the scheduling queue and registered anew as a periodic task. """ handle = self.unregisterTask(name) if handle: handle.reset(start, period, task, True) else: handle = TaskHandler(self, start, period, task, name) self.scheduleTask(handle) ## Task methods ##
def start(self): Thread.start(self)
def initialize(self): workers = [Thread(target=self._worker_thread, args=(i, ), daemon=True) for i in range(self._nr_workers)] predictors = [Thread(target=self._predictor_thread, daemon=True) for i in range(self._nr_predictors)] map_exec(Thread.start, workers) map_exec(Thread.start, predictors)
def testFakeMTRandomness(self): mutex = threading.Lock() @contextlib.contextmanager def fake_with_rng(rrr): from tartist.random import rng with mutex: backup = rng._rng rng._rng = rrr yield rrr with mutex: rng._rng = backup q = queue.Queue() def proc(): rng = tar.gen_rng() with fake_with_rng(rng): time.sleep(0.5) state = tar.get_rng().get_state() time.sleep(0.5) q.put(state) threads = [Thread(target=proc) for i in range(2)] map_exec(Thread.start, threads) map_exec(Thread.join, threads) v1, v2 = q.get(), q.get() self.assertFalse(not np.allclose(v1[1], v2[1]))
def start(self): """Start the scheduler's activity.""" self._isRunning = True Thread.start(self)
def start(self): Thread.start(self) # Automatically calls shutdown() when the returned token goes out of scope return ScopeGuard(self.shutdown)
def start(self, initial=True): # NOTE: we wait for several minutes on initial launch to not delay enigma2 startup time if initial: delay = config.plugins.autotimer.delay.value*60 else: delay = config.plugins.autotimer.interval.value*3600 self.__timer.startLongTimer(delay) if not self.isAlive(): Thread.start(self)
def start(self, initial=True): self.thread.start(initial=initial)