Skip to content

Commit

Permalink
update test code and news
Browse files Browse the repository at this point in the history
  • Loading branch information
XD Trol authored and Trol committed Jun 7, 2022
1 parent f3a947d commit 7cc22ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest
import unittest.mock
import queue as pyqueue
import textwrap
import time
import io
import itertools
Expand Down Expand Up @@ -5763,28 +5764,30 @@ def test_namespace(self):
class TestNamedResource(unittest.TestCase):
def test_global_named_resource_spawn(self):
#
# Check that global named resources in main module
# gh-90549: Check that global named resources in main module
# will not leak by a subprocess, in spawn context.
#
with os_helper.temp_dir() as tmp_dir:
source = os.path.join(tmp_dir, 'source.py')
with open(source, 'w') as f:
f.write('''if 1:
import multiprocessing as mp
testfn = os_helper.TESTFN
self.addCleanup(os_helper.unlink, testfn)
with open(testfn, 'w', encoding='utf-8') as f:
f.write(textwrap.dedent('''\
import multiprocessing as mp
ctx = mp.get_context('spawn')
ctx = mp.get_context('spawn')
global_resource = ctx.Semaphore()
global_resource = ctx.Semaphore()
def submain(): pass
def submain(): pass
if __name__ == '__main__':
p = ctx.Process(target=submain)
p.start()
p.join()
''')
rc, out, err = test.support.script_helper.assert_python_ok(source)
self.assertNotRegex(err, b'resource_tracker: There appear to be .* leaked')
if __name__ == '__main__':
p = ctx.Process(target=submain)
p.start()
p.join()
'''))
rc, out, err = test.support.script_helper.assert_python_ok(testfn)
# on error, err = 'UserWarning: resource_tracker: There appear to
# be 1 leaked semaphore objects to clean up at shutdown'
self.assertEqual(err, b'')


class MiscTestCase(unittest.TestCase):
Expand Down

0 comments on commit 7cc22ae

Please sign in to comment.