本文整理汇总了Python中multiprocessing.Manager.update方法的典型用法代码示例。如果您正苦于以下问题:Python Manager.update方法的具体用法?Python Manager.update怎么用?Python Manager.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.Manager
的用法示例。
在下文中一共展示了Manager.update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: play
# 需要导入模块: from multiprocessing import Manager [as 别名]
# 或者: from multiprocessing.Manager import update [as 别名]
def play(filename, **kwargs):
""" play(filename, soundfont=None, loops=-1) -> Starts playing filename and
returns an object to send to stop to stop it playing.
"""
playing = Manager().dict()
playing['playing'] = True
playing['filename'] = filename
playing.update(kwargs)
play_t = Process(target=_play_proc, args=(playing,))
play_t.start()
return playing, play_t
示例2: Reader
# 需要导入模块: from multiprocessing import Manager [as 别名]
# 或者: from multiprocessing.Manager import update [as 别名]
#.........这里部分代码省略.........
device.close()
time_sleep(0.05)
# Write a buffer of null bytes so the audio
# system can keep its buffer full.
# device.write(b'\x00' * device.buffer_size)
# Get and process any commands from the parent process.
if pipe.poll():
# Get the data into temp.
command = pipe.recv()
if 'getposition' in command:
pipe.send(fileobj.position)
elif 'setposition' in command:
fileobj.position = command['setposition']
except Exception as err:
print(err)
finally:
if not device.closed:
device.close()
# Set playing to False for the parent.
msg_dict['playing'] = False
def read(self, text: str, **kwargs):
""" Read the text.
"""
self._text = text
self._msg_dict['text'] = text
self._msg_dict.update(kwargs)
# After opening a new file stop the current one from playing.
self.stop()
# Pause it.
self.pause()
# Start it playing so seeking works.
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()
elif self._msg_dict.get('paused', True):
# Un-pause if paused.
self._msg_dict['paused'] = False
def stop(self):
""" stop() -> Stop playback.
示例3: AudioPlayer
# 需要导入模块: from multiprocessing import Manager [as 别名]
# 或者: from multiprocessing.Manager import update [as 别名]
#.........这里部分代码省略.........
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()
elif self._msg_dict.get('paused', True):
# Un-pause if paused.
self._msg_dict['paused'] = False
self._control_dict.update(self._msg_dict)