Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 9 additions & 6 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6810,12 +6810,15 @@ def test_std_streams_flushed_after_preload(self):
# Create a test module in the temporary directory on the child's path
# TODO: This can all be simplified once gh-126631 is fixed and we can
# use __main__ instead of a module.
os.mkdir(os.path.join(self._temp_dir, 'a'))
with open(os.path.join(self._temp_dir, 'a', '__init__.py'), "w") as f:
f.write('''if 1:
import sys
print('stdout', file=sys.stdout)
print('stderr', file=sys.stderr)\n''')
dirname = os.path.join(self._temp_dir, 'preloaded_module')
init_name = os.path.join(dirname, '__init__.py')
os.mkdir(dirname)
with open(os.path.join(init_name), "w") as f:
cmd = '''if 1:
import sys
print('stdout', file=sys.stdout)
print('stderr', file=sys.stderr)\n'''
f.write(cmd)

name = os.path.join(os.path.dirname(__file__), 'mp_preload_flush.py')
env = {'PYTHONPATH': self._temp_dir}
Expand Down
7 changes: 4 additions & 3 deletions Lib/test/mp_preload_flush.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import multiprocessing
import sys

modname = 'preloaded_module'
if __name__ == '__main__':
assert 'a' not in sys.modules
assert modname not in sys.modules
multiprocessing.set_start_method('forkserver')
multiprocessing.set_forkserver_preload(['a'])
multiprocessing.set_forkserver_preload([modname])
for _ in range(2):
p = multiprocessing.Process()
p.start()
p.join()
else:
assert 'a' in sys.modules
assert modname in sys.modules
Loading