Skip to content

Commit 1523e74

Browse files
committed
Address reviewer feedback: introduce some intermediate variables and use a
not-completely-awful name for the module to test.
1 parent 9944968 commit 1523e74

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6810,12 +6810,15 @@ def test_std_streams_flushed_after_preload(self):
68106810
# Create a test module in the temporary directory on the child's path
68116811
# TODO: This can all be simplified once gh-126631 is fixed and we can
68126812
# use __main__ instead of a module.
6813-
os.mkdir(os.path.join(self._temp_dir, 'a'))
6814-
with open(os.path.join(self._temp_dir, 'a', '__init__.py'), "w") as f:
6815-
f.write('''if 1:
6816-
import sys
6817-
print('stdout', file=sys.stdout)
6818-
print('stderr', file=sys.stderr)\n''')
6813+
dirname = os.path.join(self._temp_dir, 'preloaded_module')
6814+
init_name = os.path.join(dirname, '__init__.py')
6815+
os.mkdir(dirname)
6816+
with open(os.path.join(init_name), "w") as f:
6817+
cmd = '''if 1:
6818+
import sys
6819+
print('stdout', file=sys.stdout)
6820+
print('stderr', file=sys.stderr)\n'''
6821+
f.write(cmd)
68196822

68206823
name = os.path.join(os.path.dirname(__file__), 'mp_preload_flush.py')
68216824
env = {'PYTHONPATH': self._temp_dir}

Lib/test/mp_preload_flush.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import multiprocessing
22
import sys
33

4+
modname = 'preloaded_module'
45
if __name__ == '__main__':
5-
assert 'a' not in sys.modules
6+
assert modname not in sys.modules
67
multiprocessing.set_start_method('forkserver')
7-
multiprocessing.set_forkserver_preload(['a'])
8+
multiprocessing.set_forkserver_preload([modname])
89
for _ in range(2):
910
p = multiprocessing.Process()
1011
p.start()
1112
p.join()
1213
else:
13-
assert 'a' in sys.modules
14+
assert modname in sys.modules

0 commit comments

Comments
 (0)