Skip to content

Commit 7cc22ae

Browse files
XD TrolTrol
XD Trol
authored and
Trol
committed
update test code and news
1 parent f3a947d commit 7cc22ae

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

Lib/test/_test_multiprocessing.py

+19-16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import unittest
66
import unittest.mock
77
import queue as pyqueue
8+
import textwrap
89
import time
910
import io
1011
import itertools
@@ -5763,28 +5764,30 @@ def test_namespace(self):
57635764
class TestNamedResource(unittest.TestCase):
57645765
def test_global_named_resource_spawn(self):
57655766
#
5766-
# Check that global named resources in main module
5767+
# gh-90549: Check that global named resources in main module
57675768
# will not leak by a subprocess, in spawn context.
57685769
#
5769-
with os_helper.temp_dir() as tmp_dir:
5770-
source = os.path.join(tmp_dir, 'source.py')
5771-
with open(source, 'w') as f:
5772-
f.write('''if 1:
5773-
import multiprocessing as mp
5770+
testfn = os_helper.TESTFN
5771+
self.addCleanup(os_helper.unlink, testfn)
5772+
with open(testfn, 'w', encoding='utf-8') as f:
5773+
f.write(textwrap.dedent('''\
5774+
import multiprocessing as mp
57745775
5775-
ctx = mp.get_context('spawn')
5776+
ctx = mp.get_context('spawn')
57765777
5777-
global_resource = ctx.Semaphore()
5778+
global_resource = ctx.Semaphore()
57785779
5779-
def submain(): pass
5780+
def submain(): pass
57805781
5781-
if __name__ == '__main__':
5782-
p = ctx.Process(target=submain)
5783-
p.start()
5784-
p.join()
5785-
''')
5786-
rc, out, err = test.support.script_helper.assert_python_ok(source)
5787-
self.assertNotRegex(err, b'resource_tracker: There appear to be .* leaked')
5782+
if __name__ == '__main__':
5783+
p = ctx.Process(target=submain)
5784+
p.start()
5785+
p.join()
5786+
'''))
5787+
rc, out, err = test.support.script_helper.assert_python_ok(testfn)
5788+
# on error, err = 'UserWarning: resource_tracker: There appear to
5789+
# be 1 leaked semaphore objects to clean up at shutdown'
5790+
self.assertEqual(err, b'')
57885791

57895792

57905793
class MiscTestCase(unittest.TestCase):

0 commit comments

Comments
 (0)