Skip to content

Avoid the multiprocessing forkserver method #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/etcd/tests/integration/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ def test_reconnet_fails(self):


class TestWatch(EtcdIntegrationTest):
# On macOS and newly non-macOS POSIX systems (since Python 3.14),
# the default method has been changed to forkserver.
# The code in this test does not work with it,
# hence the explicit change to 'fork'
# See https://github.com/python/cpython/issues/125714
if multiprocessing.get_start_method() == "forkserver":
_mp_context = multiprocessing.get_context(method="fork")
else:
_mp_context = multiprocessing.get_context()

def test_watch(self):
"""INTEGRATION: Receive a watch event from other process"""

Expand All @@ -259,15 +269,15 @@ def watch_value(key, queue):
c = etcd.Client(port=6001)
queue.put(c.watch(key).value)

changer = multiprocessing.Process(
changer = self._mp_context.Process(
target=change_value,
args=(
"/test-key",
"new-test-value",
),
)

watcher = multiprocessing.Process(target=watch_value, args=("/test-key", queue))
watcher = self._mp_context.Process(target=watch_value, args=("/test-key", queue))

watcher.start()
time.sleep(1)
Expand Down Expand Up @@ -301,15 +311,15 @@ def watch_value(key, index, queue):
for i in range(0, 3):
queue.put(c.watch(key, index=index + i).value)

proc = multiprocessing.Process(
proc = self._mp_context.Process(
target=change_value,
args=(
"/test-key",
"test-value3",
),
)

watcher = multiprocessing.Process(
watcher = self._mp_context.Process(
target=watch_value, args=("/test-key", original_index, queue)
)

Expand Down Expand Up @@ -346,9 +356,9 @@ def watch_value(key, queue):
event = next(c.eternal_watch(key)).value
queue.put(event)

changer = multiprocessing.Process(target=change_value, args=("/test-key",))
changer = self._mp_context.Process(target=change_value, args=("/test-key",))

watcher = multiprocessing.Process(target=watch_value, args=("/test-key", queue))
watcher = self._mp_context.Process(target=watch_value, args=("/test-key", queue))

watcher.start()
changer.start()
Expand Down Expand Up @@ -383,15 +393,15 @@ def watch_value(key, index, queue):
for i in range(0, 3):
queue.put(next(iterevents).value)

proc = multiprocessing.Process(
proc = self._mp_context.Process(
target=change_value,
args=(
"/test-key",
"test-value3",
),
)

watcher = multiprocessing.Process(
watcher = self._mp_context.Process(
target=watch_value, args=("/test-key", original_index, queue)
)

Expand Down
Loading