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


Python Manager.update方法代码示例

本文整理汇总了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
开发者ID:,项目名称:,代码行数:17,代码来源:

示例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.
开发者ID:zepto,项目名称:clipspeak,代码行数:69,代码来源:speaker.py

示例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)
开发者ID:,项目名称:,代码行数:70,代码来源:


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