本文整理汇总了Python中viewer.Viewer.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Python Viewer.shutdown方法的具体用法?Python Viewer.shutdown怎么用?Python Viewer.shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类viewer.Viewer
的用法示例。
在下文中一共展示了Viewer.shutdown方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Scheduler
# 需要导入模块: from viewer import Viewer [as 别名]
# 或者: from viewer.Viewer import shutdown [as 别名]
class Scheduler(object):
'''
Schedules the content in the playlist to be displayed.
The scheduling occurs in its own thread. To ensure thread safety,
the play list should be modified using the
modify_playlist_atomically() method.
'''
def __init__(self):
self.logger = logging.getLogger(__name__)
self.logger.debug('Initializing scheduler')
self.viewer = Viewer()
self._playlist = []
self._playlist_lock = Lock()
self.running = False
def start(self):
self.logger.debug('Starting scheduling')
self.running = True
def is_interrupted_func(content):
return content not in self._playlist
def schedule_worker(scheduler):
self.logger.debug('Scheduling thread started')
index = 0
while scheduler.running:
lock = scheduler._playlist_lock
lock.acquire()
try:
playlist = scheduler._playlist
content_index = index % len(playlist)
content = playlist[content_index]
finally:
lock.release()
self.logger.debug('Scheduler began displaying %s', content)
scheduler.viewer.display_content(content, is_interrupted_func)
index += 1
scheduler.viewer.shutdown()
self.logger.debug('Exiting scheduler worker thread')
self.work_thread = Thread(target=schedule_worker, args=(self,))
self.work_thread.daemon = True
self.work_thread.start()
def shutdown(self):
self.logger.debug('Scheduler shutdown called')
self.running = False
self.viewer.shutdown()
self.logger.debug('Scheduler waiting for worker thread to stop')
self.work_thread.join()
self.logger.debug('Scheduler shut down complete')
def modify_playlist_atomically(self, modifier_function):
self.logger.debug('Modifying scheduler playlist atomically')
self._playlist_lock.acquire()
try:
modifier_function(self._playlist)
finally:
self._playlist_lock.release()