本文整理汇总了Python中clock.Clock.run方法的典型用法代码示例。如果您正苦于以下问题:Python Clock.run方法的具体用法?Python Clock.run怎么用?Python Clock.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clock.Clock
的用法示例。
在下文中一共展示了Clock.run方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import run [as 别名]
class PiGlow_Status_Server:
def __init__ (self):
self.cfg = PiGlow_Status_Config ()
self.commands = PiGlow_Status_Commands ()
self.idle_job = self.commands.CLOCK
self.jobs = []
self.running = None
self.locked_thread = None
self.check_jobs_thread = None
self.socket_manager_thread = None
self.piglow = None
self.clock = None
self.alert = None
self.in_progress = None
self.job_interval = 0.1
self.quiet_time = False
def start (self):
"""Creates the socket and starts the threads"""
try:
self.piglow = PiGlow ()
except IOError as e:
if e[0] == errno.EACCES:
print >> sys.stderr, "Permission denied, try running as root"
else:
print >> sys.stderr, "Unknown error accessing the PiGlow"
sys.exit (1)
self.piglow.all (0)
self.clock = Clock (self.piglow)
self.alert = Alert (self.piglow)
self.in_progress = In_Progress (self.piglow)
address = (self.cfg.HOST, self.cfg.PORT)
serversock = socket (AF_INET, SOCK_STREAM)
serversock.setsockopt (SOL_SOCKET, SO_REUSEADDR, 1)
serversock.bind (address)
serversock.listen (5)
self.check_jobs_thread = Thread (None, self.check_jobs, None, ())
self.socket_manager_thread = Thread (None, self.socket_manager, None, (serversock, ))
self.start_threads ()
while self.running == True:
sleep (1)
self.stop ()
def stop (self):
"""Closes the threads and returns"""
self.stop_threads ()
self.piglow.all (0)
def start_threads (self):
"""Starts the threads"""
self.running = True
self.check_jobs_thread.start ()
self.socket_manager_thread.start ()
def stop_threads (self):
"""Stops the threads"""
self.running = False
self.unlock ()
try:
self.check_jobs_thread.join ()
except (KeyboardInterrupt, SystemExit):
pass
try:
self.socket_manager_thread.join ()
except (KeyboardInterrupt, SystemExit):
pass
def check_jobs (self):
"""Performs the actions in the job list"""
while self.running == True:
if self.quit_requested ():
self.running = False
break
#.........这里部分代码省略.........