Skip to content

Commit 8366b84

Browse files
author
Charles-François Natali
committed
Followup to issue #11867: Use socketpair(), since FreeBSD < 8 doesn't really
support multiprocessing.Event.
1 parent 5879ca1 commit 8366b84

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

Lib/test/test_mailbox.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
import fcntl
1616
except ImportError:
1717
pass
18-
try:
19-
import multiprocessing
20-
except ImportError:
21-
multiprocessing = None
2218

2319
# Silence Py3k warning
2420
rfc822 = test_support.import_module('rfc822', deprecated=True)
@@ -870,35 +866,36 @@ def test_add_and_close(self):
870866
self._box = self._factory(self._path)
871867

872868
@unittest.skipUnless(hasattr(os, 'fork'), "Test needs fork().")
873-
@unittest.skipUnless(multiprocessing, "Test needs multiprocessing.")
869+
@unittest.skipUnless(hasattr(socket, 'socketpair'), "Test needs socketpair().")
874870
def test_lock_conflict(self):
875871
# Fork off a child process that will lock the mailbox temporarily,
876872
# 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)
879876

880877
pid = os.fork()
881878
if pid == 0:
882879
# child
883880
try:
884881
# lock the mailbox, and signal the parent it can proceed
885882
self._box.lock()
886-
ready.set()
883+
c.send(b'c')
887884

888885
# wait until the parent is done, and unlock the mailbox
889-
done.wait(5)
886+
c.recv(1)
890887
self._box.unlock()
891888
finally:
892889
os._exit(0)
893890

894891
# In the parent, wait until the child signals it locked the mailbox.
895-
ready.wait(5)
892+
p.recv(1)
896893
try:
897894
self.assertRaises(mailbox.ExternalClashError,
898895
self._box.lock)
899896
finally:
900897
# Signal the child it can now release the lock and exit.
901-
done.set()
898+
p.send(b'p')
902899
# Wait for child to exit. Locking should now succeed.
903900
exited_pid, status = os.waitpid(pid, 0)
904901

0 commit comments

Comments
 (0)