本文整理汇总了Python中multiprocessing.Manager.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Manager.clear方法的具体用法?Python Manager.clear怎么用?Python Manager.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.Manager
的用法示例。
在下文中一共展示了Manager.clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AudioPlayer
# 需要导入模块: from multiprocessing import Manager [as 别名]
# 或者: from multiprocessing.Manager import clear [as 别名]
#.........这里部分代码省略.........
pipe.send(fileobj.loop_count)
except Exception as err:
print(err)
finally:
if not device.closed:
device.close()
except IOError as err:
from time import sleep
msg_dict['error'] = err
msg_dict['info'] = ''
msg_dict['length'] = 0
print(err)
finally:
try:
# Set playing to False for the parent.
msg_dict['playing'] = False
except BrokenPipeError:
pass
def open(self, filename: str, **kwargs):
""" open(filename) -> Open an audio file to play.
"""
# Stop the current file from playing.
self.stop()
# Set the new filename.
self._filename = filename
# Reset the message dictionary so none of the old info is
# re-used.
self._msg_dict.clear()
# Fill the message dictionary with the new info.
self._msg_dict['show_position'] = self._show_position
self._msg_dict['filename'] = filename
self._msg_dict.update(kwargs)
self._control_dict.update(self._msg_dict)
# Pause it so when we call play later it will start the player
# but not the audio playback. Call play again to start audio
# playback.
self.pause()
# Start the playback process in a paused state. Requires a
# second call to play to un-pause.
self.play()
def play(self):
""" play() -> Start playback.
"""
if not self._msg_dict.get('playing', False):
# Set playing to True for the child process.
self._msg_dict['playing'] = True
# Open a new process to play a file in the background.
self._play_p = Process(target=self._play_proc,
args=(self._msg_dict, self._player_conn))
# Start the process.
self._play_p.start()