本文整理汇总了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()
示例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()