(self)
| 1230 | @support.requires_fork() |
| 1231 | @unittest.skipUnless(hasattr(socket, 'socketpair'), "Test needs socketpair().") |
| 1232 | def test_lock_conflict(self): |
| 1233 | # Fork off a child process that will lock the mailbox temporarily, |
| 1234 | # unlock it and exit. |
| 1235 | c, p = socket.socketpair() |
| 1236 | self.addCleanup(c.close) |
| 1237 | self.addCleanup(p.close) |
| 1238 | |
| 1239 | pid = os.fork() |
| 1240 | if pid == 0: |
| 1241 | # child |
| 1242 | try: |
| 1243 | # lock the mailbox, and signal the parent it can proceed |
| 1244 | self._box.lock() |
| 1245 | c.send(b'c') |
| 1246 | |
| 1247 | # wait until the parent is done, and unlock the mailbox |
| 1248 | c.recv(1) |
| 1249 | self._box.unlock() |
| 1250 | finally: |
| 1251 | os._exit(0) |
| 1252 | |
| 1253 | # In the parent, wait until the child signals it locked the mailbox. |
| 1254 | p.recv(1) |
| 1255 | try: |
| 1256 | self.assertRaises(mailbox.ExternalClashError, |
| 1257 | self._box.lock) |
| 1258 | finally: |
| 1259 | # Signal the child it can now release the lock and exit. |
| 1260 | p.send(b'p') |
| 1261 | # Wait for child to exit. Locking should now succeed. |
| 1262 | support.wait_process(pid, exitcode=0) |
| 1263 | |
| 1264 | self._box.lock() |
| 1265 | self._box.unlock() |
| 1266 | |
| 1267 | def test_relock(self): |
| 1268 | # Test case for bug #1575506: the mailbox class was locking the |
nothing calls this directly
no test coverage detected