Skip to content

Commit 42a7bcf

Browse files
committed
Fix tests of Fediverse plugin on Python >=3.14
which does not use 'fork' as the default multiprocessing method anymore, and we need a Manager from the same context in order for tests to work.
1 parent 454b800 commit 42a7bcf

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

plugins/Fediverse/test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@
3333
import json
3434
import functools
3535
import contextlib
36-
from multiprocessing import Manager
3736

38-
from supybot import conf, log, utils
37+
from supybot import conf, log, utils, world
3938
from supybot.test import ChannelPluginTestCase, network
4039

4140
from . import activitypub as ap
@@ -125,7 +124,7 @@ def newf(hostname):
125124

126125
@contextlib.contextmanager
127126
def mockRequests(self, expected_requests):
128-
with Manager() as m:
127+
with world.SUPYPROCESS_MULTIPROCESSING_CONTEXT.Manager() as m:
129128
expected_requests = m.list(list(expected_requests))
130129
original_getUrlContent = utils.web.getUrlContent
131130

src/world.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,15 @@ def __init__(self, *args, **kwargs):
6464
super(SupyThread, self).__init__(*args, **kwargs)
6565
log.debug('Spawning thread %q.', self.getName())
6666

67+
SUPYPROCESS_MULTIPROCESSING_CONTEXT = multiprocessing.get_context('fork')
68+
"""
69+
Which :mod:`multiprocessing` is used to run :class:`SupyProcess`
70+
71+
Currently this is (unfortunately) ``fork`` because functions running in forks
72+
often need to read the global state.
73+
"""
6774
processesSpawned = 1 # Starts at one for the initial process.
68-
class SupyProcess(multiprocessing.get_context('fork').Process):
75+
class SupyProcess(SUPYPROCESS_MULTIPROCESSING_CONTEXT.Process):
6976
def __init__(self, *args, **kwargs):
7077
global processesSpawned
7178
processesSpawned += 1

0 commit comments

Comments
 (0)