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


Python mailbox.ExternalClashError方法代码示例

本文整理汇总了Python中mailbox.ExternalClashError方法的典型用法代码示例。如果您正苦于以下问题:Python mailbox.ExternalClashError方法的具体用法?Python mailbox.ExternalClashError怎么用?Python mailbox.ExternalClashError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mailbox的用法示例。


在下文中一共展示了mailbox.ExternalClashError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_lock_conflict

# 需要导入模块: import mailbox [as 别名]
# 或者: from mailbox import ExternalClashError [as 别名]
def test_lock_conflict(self):
        # Fork off a subprocess that will lock the file for 2 seconds,
        # unlock it, and then exit.
        if not hasattr(os, 'fork'):
            return
        pid = os.fork()
        if pid == 0:
            # In the child, lock the mailbox.
            self._box.lock()
            time.sleep(2)
            self._box.unlock()
            os._exit(0)

        # In the parent, sleep a bit to give the child time to acquire
        # the lock.
        time.sleep(0.5)
        try:
            self.assertRaises(mailbox.ExternalClashError,
                              self._box.lock)
        finally:
            # Wait for child to exit.  Locking should now succeed.
            exited_pid, status = os.waitpid(pid, 0)

        self._box.lock()
        self._box.unlock() 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:27,代码来源:test_mailbox.py

示例2: test_lock_conflict

# 需要导入模块: import mailbox [as 别名]
# 或者: from mailbox import ExternalClashError [as 别名]
def test_lock_conflict(self):
        # Fork off a child process that will lock the mailbox temporarily,
        # unlock it and exit.
        c, p = socket.socketpair()
        self.addCleanup(c.close)
        self.addCleanup(p.close)

        pid = os.fork()
        if pid == 0:
            # child
            try:
                # lock the mailbox, and signal the parent it can proceed
                self._box.lock()
                c.send(b'c')

                # wait until the parent is done, and unlock the mailbox
                c.recv(1)
                self._box.unlock()
            finally:
                os._exit(0)

        # In the parent, wait until the child signals it locked the mailbox.
        p.recv(1)
        try:
            self.assertRaises(mailbox.ExternalClashError,
                              self._box.lock)
        finally:
            # Signal the child it can now release the lock and exit.
            p.send(b'p')
            # Wait for child to exit.  Locking should now succeed.
            exited_pid, status = os.waitpid(pid, 0)

        self._box.lock()
        self._box.unlock() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:36,代码来源:test_mailbox.py


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