|
15 | 15 | import fcntl
|
16 | 16 | except ImportError:
|
17 | 17 | pass
|
18 |
| -try: |
19 |
| - import multiprocessing |
20 |
| -except ImportError: |
21 |
| - multiprocessing = None |
22 | 18 |
|
23 | 19 | # Silence Py3k warning
|
24 | 20 | rfc822 = test_support.import_module('rfc822', deprecated=True)
|
@@ -870,35 +866,36 @@ def test_add_and_close(self):
|
870 | 866 | self._box = self._factory(self._path)
|
871 | 867 |
|
872 | 868 | @unittest.skipUnless(hasattr(os, 'fork'), "Test needs fork().")
|
873 |
| - @unittest.skipUnless(multiprocessing, "Test needs multiprocessing.") |
| 869 | + @unittest.skipUnless(hasattr(socket, 'socketpair'), "Test needs socketpair().") |
874 | 870 | def test_lock_conflict(self):
|
875 | 871 | # Fork off a child process that will lock the mailbox temporarily,
|
876 | 872 | # unlock it and exit.
|
877 |
| - ready = multiprocessing.Event() |
878 |
| - done = multiprocessing.Event() |
| 873 | + c, p = socket.socketpair() |
| 874 | + self.addCleanup(c.close) |
| 875 | + self.addCleanup(p.close) |
879 | 876 |
|
880 | 877 | pid = os.fork()
|
881 | 878 | if pid == 0:
|
882 | 879 | # child
|
883 | 880 | try:
|
884 | 881 | # lock the mailbox, and signal the parent it can proceed
|
885 | 882 | self._box.lock()
|
886 |
| - ready.set() |
| 883 | + c.send(b'c') |
887 | 884 |
|
888 | 885 | # wait until the parent is done, and unlock the mailbox
|
889 |
| - done.wait(5) |
| 886 | + c.recv(1) |
890 | 887 | self._box.unlock()
|
891 | 888 | finally:
|
892 | 889 | os._exit(0)
|
893 | 890 |
|
894 | 891 | # In the parent, wait until the child signals it locked the mailbox.
|
895 |
| - ready.wait(5) |
| 892 | + p.recv(1) |
896 | 893 | try:
|
897 | 894 | self.assertRaises(mailbox.ExternalClashError,
|
898 | 895 | self._box.lock)
|
899 | 896 | finally:
|
900 | 897 | # Signal the child it can now release the lock and exit.
|
901 |
| - done.set() |
| 898 | + p.send(b'p') |
902 | 899 | # Wait for child to exit. Locking should now succeed.
|
903 | 900 | exited_pid, status = os.waitpid(pid, 0)
|
904 | 901 |
|
|
0 commit comments