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


Python Timer.cancel方法代码示例

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


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

示例1: run

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
  def run(self, app, type):
    # Invoke wren and run the test.
    test_arg = self.path
    if type == "api test":
      # Just pass the suite name to API tests.
      test_arg = basename(splitext(test_arg)[0])

    proc = Popen([app, test_arg], stdin=PIPE, stdout=PIPE, stderr=PIPE)

    # If a test takes longer than two seconds, kill it.
    #
    # This is mainly useful for running the tests while stress testing the GC,
    # which can make a few pathological tests much slower.
    timed_out = [False]
    def kill_process(p):
      timed_out[0] = True
      p.kill()

    timer = Timer(2, kill_process, [proc])

    try:
      timer.start()
      out, err = proc.communicate(self.input_bytes)

      if timed_out[0]:
        self.fail("Timed out.")
      else:
        self.validate(type == "example", proc.returncode, out, err)
    finally:
      timer.cancel()
开发者ID:Rohansi,项目名称:wren,代码行数:32,代码来源:test.py

示例2: __init__

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
class OpeningState:
    def __init__(self, door_model):
        self.door_model = door_model

    def door_position_changed(self, new_position):
        if new_position == DOOR_POSITION_OPEN:
            self.door_model.set_new_state("Open")
        elif new_position == DOOR_POSITION_CLOSED:
            self.door_model.set_new_state("Closed")

    def enter(self):
        logger.debug("State 'opening' entered")
        self.timer = Timer(self.door_model.transit_time, self._transit_timeout)
        self.timer.start()

    def exit(self):
        logger.debug("State 'opening' exited")
        if self.timer:
            self.timer.cancel()
            self.timer = False

    def _transit_timeout(self):
        logger.info("Transit timeout reached")
        self.timer = False
        self.door_model.set_new_state("Intermediate")
开发者ID:Mik-,项目名称:garage-door-controller,代码行数:27,代码来源:opening_state.py

示例3: PeriodicTimer

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
class PeriodicTimer(object):

    def __init__(self, frequency=60, *args, **kwargs):
        self.is_stopped = Event()
        self.is_stopped.clear()

        self.interval = frequency
        self._timer = Timer(self.frequency, self._check_for_event, ())
        self._timer.daemon = True

    @property
    def interval(self):
        return self.frequency

    @interval.setter
    def interval(self, frequency):
        self.frequency = frequency
        self.stop()
        try:
            if self._timer:
                self._timer.cancel()
                del(self._timer)
        except AttributeError, ex:
            pass
        self._timer = Timer(self.frequency, self._check_for_event, ())
        return self.frequency
开发者ID:chrisleck-old-personal,项目名称:pytomation,代码行数:28,代码来源:periodic_timer.py

示例4: TimerMixIn

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
class TimerMixIn(object):
  
    def __init__(self, *argl, **argd):
        super(TimerMixIn,self).__init__(*argl,**argd)
        self.timer = None
        self.timerSuccess = True
          
    def startTimer(self, secs):
        if self.timer is not None:
            self.cancelTimer()
        self.timer = Timer(secs, self.__handleTimerDone)
        self.timerSuccess = False
        self.timer.start()
  
    def cancelTimer(self):
        if self.timer is not None and self.timer:
             self.timer.cancel()
             self.timer = None
             self.timerSuccess = False
  
    def timerRunning(self):
        return self.timer is not None
        
    def timerWasCancelled(self):
        return not self.timerSuccess
  
    def __handleTimerDone(self):
        self.scheduler.wakeThread(self)
        self.timer = None
        self.timerSuccess = True
开发者ID:casibbald,项目名称:kamaelia,代码行数:32,代码来源:TimerMixIn.py

示例5: run

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
def run(data, d=None):
	global timer
	print(data)

	if data == "ring":
		if int(d) == 1:
			if timer:
				timer.cancel()

			timer = Timer(60, genugdavon)
			timer.start()

			check = Thread(target=check_locks)
			check.start()

			putfile('/sys/class/gpio/gpio11/value', '0')

			playsound("/root/ring-bb.wav")
		else:
			playsound("/root/ring-fis.wav")
	

	if data == "open":
#		if not locked_oben:
		playsound("/root/open.wav")
	
	if data == "summ":
		if timer:
			timer.cancel()

#		if not locked_oben:
		putfile('/sys/class/gpio/gpio11/value', '1')
		playsound("/root/summ.wav")
开发者ID:Chaotikum,项目名称:klingel,代码行数:35,代码来源:klingel.py

示例6: _winsetscreen

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
        def _winsetscreen(state):
            import win32gui
            import win32con
            from os import getpid, system
            from threading import Timer

            MONITOR_OFF = 2
            MONITOR_ON = -1

            def _winforceexit():
                pid = getpid()
                system('taskkill /pid %s /f' % pid)

            t = Timer(1, _winforceexit)
            t.start()
            SC_MONITORPOWER = 0xF170
            if state:
                win32gui.SendMessage(win32con.HWND_BROADCAST,
                                     win32con.WM_SYSCOMMAND,
                                     SC_MONITORPOWER,
                                     MONITOR_ON)
            else:
                win32gui.SendMessage(win32con.HWND_BROADCAST,
                                     win32con.WM_SYSCOMMAND,
                                     SC_MONITORPOWER,
                                     MONITOR_OFF)
            t.cancel()
开发者ID:infamy,项目名称:Avocado-Daemon,代码行数:29,代码来源:avocado.py

示例7: RepeatedTimer

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
class RepeatedTimer(object):

    def __init__(self, interval, function, tag=None):
        self._timer = None
        self.interval = interval
        self.function = function
        self.tag = tag
        self.is_running = False
        self.start()

    def _run(self):
        self.is_running = False
        self.start()
        self.function("Currently working on %s" %
                      self.tag, show=self.tag is not None)

    def start(self):
        if not self.is_running:
            self._timer = Timer(self.interval, self._run)
            self._timer.start()
            self.is_running = True

    def stop(self):
        self._timer.cancel()
        self.is_running = False
开发者ID:simon-gunacker,项目名称:timetracker,代码行数:27,代码来源:tt.py

示例8: InfiniteTimer

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
class InfiniteTimer():
    """A Timer class that does not stop, unless you want it to."""

    def __init__(self, seconds, target):
        self._should_continue = False
        self.is_running = False
        self.seconds = seconds
        self.target = target
        self.thread = None

    def _handle_target(self):
        self.is_running = True
        self.target()
        self.is_running = False
        self._start_timer()

    def _start_timer(self):
        if self._should_continue:  # Code could have been running when cancel was called.
            self.thread = Timer(self.seconds, self._handle_target)
            self.thread.start()

    def start(self):
        if not self._should_continue and not self.is_running:
            self._should_continue = True
            self._start_timer()
        else:
            print("Timer already started or running, please wait if you're restarting.")

    def cancel(self):
        if self.thread is not None:
            # Just in case thread is running and cancel fails.
            self._should_continue = False
            self.thread.cancel()
        else:
            print("Timer never started or failed to initialize.")
开发者ID:MediaKraken,项目名称:MediaKraken_Deployment,代码行数:37,代码来源:common_timer.py

示例9: test_loop_with_timeout

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
def test_loop_with_timeout(test_function, timeout_seconds, loop_count_limit, logger):
    for i in range(0, loop_count_limit):
        try:
            t = Timer(timeout_seconds, force_timeout)
            t.start()
            if test_function():
                t.cancel()
                return True
            t.cancel()
        except socket.error:
            logger.error(
                str(timeout_seconds)
                + " seconds time out has occur in "
                + test_function.__name__
                + " Loop"
                + str(i + 1)
                + ". Rerun test module."
            )
        except httplib.BadStatusLine:
            logger.error(
                str(timeout_seconds)
                + " seconds time out has occur in "
                + test_function.__name__
                + " Loop"
                + str(i + 1)
                + ". Rerun test module."
            )
    return False
开发者ID:yalinjae,项目名称:seleniumTest_cart,代码行数:30,代码来源:commDispMobile.py

示例10: wait_status

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
    def wait_status(self, status=win32service.SERVICE_RUNNING, timeout=SERVICE_WAIT_TIMEOUT):
        abort = Event()
        abort.clear()

        def die():
            abort.set()

        timer = Timer(timeout, die)
        timer.start()

        current = None
        while True:
            if abort.is_set():
                # If timeout is hit we abort.
                log.warning("Timeout hit waiting service for status %s, current status %s",
                            status, current['CurrentState'])
                return

            current = win32service.QueryServiceStatusEx(self.service)

            if current['CurrentState'] == status:
                timer.cancel()
                return

            time.sleep(1)
开发者ID:0x829a74bc,项目名称:detekt,代码行数:27,代码来源:service.py

示例11: pclose

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
def pclose(pipe):
    def kill_pipe():
        pipe.kill()
    t = Timer(5., kill_pipe)
    t.start()
    pipe.terminate()
    t.cancel()
开发者ID:casmacat,项目名称:moses-mt-server,代码行数:9,代码来源:server_adaptive_GIZA.py

示例12: Interrupt

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
class Interrupt(object):
    def __init__(self, interval, function, *args, **kwargs):
        self._timer = None
        self.interval = interval
        self.function = function
        self.args = args
        self.kwargs = kwargs
        self.is_running = False
        self.start()

    def _run(self):
        self.is_running = False
        self.start()
        self.function(*self.args, **self.kwargs)

    def start(self):
        if not self.is_running:
            self._timer = Timer(self.interval, self._run)
            self._timer.daemon = True
            self._timer.start()
            self.is_running = True

    def stop(self):
        self._timer.cancel()
        self.is_running = False
开发者ID:dlavell,项目名称:tower,代码行数:27,代码来源:utils.py

示例13: RepeatedTimer

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
class RepeatedTimer(object):
    def __init__(self, interval, function, *args, **kwargs):
        self._timer     = None
        self.interval   = interval
        self.function   = function
        self.args       = args
        self.kwargs     = kwargs
        self.is_running = False
        self.con        = None
        self.start()

    def _run(self):
        self.is_running = False
        self.start()
        self.function(*self.args, **self.kwargs)

    def start(self):
        if not self.is_running:
            self._timer = Timer(self.interval, self._run)
            self._timer.start()
            self.is_running = True
            self.con = sqlite3.connect(args.dbname)

    def stop(self):
        self._timer.cancel()
#        self.con.close()
        self.is_running = False
开发者ID:cabletie,项目名称:tanklevel,代码行数:29,代码来源:adcpiv2.py

示例14: InternalServer

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
class InternalServer(HTTPServer):

    def kill_me(self):
        self.shutdown()
        logging.info("The server's life has come to an end, pid: {}".format(os.getpid()))


    def reset_selfdestruct_timer(self):
        if self.self_destruct_timer:
            self.self_destruct_timer.cancel()

        self.self_destruct_timer = Timer(LIFESPAN, self.kill_me)
        self.self_destruct_timer.start()


    def __init__(self, server_address, RequestHandlerClass, 
                 bind_and_activate=True):

        HTTPServer.__init__(self, server_address, RequestHandlerClass, 
                            bind_and_activate=bind_and_activate)
        
        self.self_destruct_timer = None
        self.clients = 1
        self.reset_selfdestruct_timer()


    def suicide(self):
        self.clients -= 1
        if self.clients == 0:
            if self.self_destruct_timer is not None:
                self.self_destruct_timer.cancel()

            quick_and_painless_timer = Timer(0.1, self.kill_me)
            quick_and_painless_timer.start()
开发者ID:Mapotempo,项目名称:omim,代码行数:36,代码来源:testserver.py

示例15: CallbackModule

# 需要导入模块: from threading import Timer [as 别名]
# 或者: from threading.Timer import cancel [as 别名]
class CallbackModule(CallbackBase):

    CALLBACK_VERSION = 2.0
    CALLBACK_TYPE = 'beautifier'
    CALLBACK_NAME = 'long_running_operation_status'

    # Monkey patch to turn off default callback logging
    CallbackBase._original_dump_results = CallbackBase._dump_results
    CallbackBase._dump_results = fixed_dump_results

    def __init__(self, display=None):
        super(CallbackModule, self).__init__(display=display)
        self.__timer_interval = 20.0
        self.__progress_timer = Timer(self.__timer_interval, self.__in_progress_message)

    def __in_progress_message(self):
        self._display.display('status: ["operation in progress..."]', color='yellow')
        self.__progress_timer = Timer(self.__timer_interval, self.__in_progress_message)
        self.__progress_timer.start()

    def v2_playbook_on_task_start(self, task, is_conditional):
        self.__progress_timer.cancel()
        self.__progress_timer = Timer(self.__timer_interval, self.__in_progress_message)
        self.__progress_timer.start()

    def v2_playbook_on_stats(self, stats):
        self.__progress_timer.cancel()
开发者ID:shadow-robot,项目名称:sr-build-tools,代码行数:29,代码来源:log_beautifier.py


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