Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-104090: Update Resource Tracker to return exit code based on resource leaked found or not#106807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

bityob
Copy link
Contributor

@bityobbityob commentedJul 16, 2023
edited by pitrou
Loading

  1. Add tests to catch the resource leak bug incollectedDurations and verified that it fails without the fix
Show output
$ ./python -m unittest test.test_concurrent_futures.FailingInitializerResourcesTest./home/user/cpython/Lib/multiprocessing/resource_tracker.py:228: UserWarning: resource_tracker: There appear to be 3 leaked semaphore objects to clean up at shutdown  warnings.warn('resource_tracker: There appear to be %d'FTraceback (most recent call last):  File"/home/user/cpython/Lib/multiprocessing/util.py", line 300,in _run_finalizersfinalizer()  File"/home/user/cpython/Lib/multiprocessing/util.py", line 224,in __call__    res = self._callback(*self._args,**self._kwargs)          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File"/home/user/cpython/Lib/multiprocessing/synchronize.py", line 87,in _cleanup    sem_unlink(name)FileNotFoundError: [Errno 2] No such file or directory...======================================================================FAIL: test_forkserver (test.test_concurrent_futures.FailingInitializerResourcesTest.test_forkserver)----------------------------------------------------------------------Traceback (most recent call last):  File"/home/user/cpython/Lib/test/test_concurrent_futures.py", line 318,in test_forkserver    self._test(ProcessPoolForkserverFailingInitializerTest)  File"/home/user/cpython/Lib/test/test_concurrent_futures.py", line 312,in _test    self.assertEqual(_resource_tracker._exitcode, 0)AssertionError: 256!= 0======================================================================FAIL: test_spawn (test.test_concurrent_futures.FailingInitializerResourcesTest.test_spawn)----------------------------------------------------------------------Traceback (most recent call last):  File"/home/user/cpython/Lib/test/test_concurrent_futures.py", line 315,in test_spawn    self._test(ProcessPoolSpawnFailingInitializerTest)  File"/home/user/cpython/Lib/test/test_concurrent_futures.py", line 312,in _test    self.assertEqual(_resource_tracker._exitcode, 0)AssertionError: 256!= 0----------------------------------------------------------------------Ran 2 testsin 0.727sFAILED (failures=2)0.33s
  1. Add returning exit code fromresource_tracker.py based on the cleanup result, so we can check what was the result
  2. Add tests for Resource Tracker exit code based on leaked/no leaked resources

@bedevere-bot
Copy link

Most changes to Pythonrequire a NEWS entry.

Please add it using theblurb_it web app or theblurb command-line tool.

@iritkatrieliritkatriel requested a review frompitrouJuly 17, 2023 15:59

# Reset exit code value
_resource_tracker._exitcode = None
exit_code_assert = self.assertNotEqual
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is a bit confusing. Also, it will match any non-zero exit code which might not be desired (other problems may return some code not in{0, 1}). How about simplyexpected_exit_code = 0 if delete_queue else 1?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hey,
I fixed the test and fixed the code too.
Since I saved the exit status (which was 256 when the exit code was 1),
so now the code saves the exit code and verifies it to0/1
Thanks

Comment on lines 300 to 305
runner = unittest.TextTestRunner()
result = runner.run(test_class('test_initializer'))

self.assertEqual(result.testsRun, 1)
self.assertEqual(result.failures, [])
self.assertEqual(result.errors, [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Uhm, why not do the simple thing and add these checks somewhere inFailingInitializerMixin?
It should also avoid running those tests twice (which I assume this does).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The result object exists when we run the test using Test Runner, which is not the case onFailingInitializerMixin.
This is used for safety, ensuring the inner test passed before we check the resource tracker

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, but this is needlessly complex (and might interfere with other test options/customizations). Let's do the check at the end of said tests.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@pitrou I don't understand how you want those checks to be since we can check it only after a test run with the returned result, which is not the case in regular tests. Anyway, I'm removing those checks since it's not mandatory and just for safety

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I honestly don't understand what the difficulty would be. You can make the resource tracker stop at the end of the test, or at the end of the testcase (in a teardown method for example).

Comment on lines 5564 to 5565
Test the exit code of the resource tracker based on if there were left leaked resources when we stop the process.
If not leaked resources were found, exit code should be 0, otherwise 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for the comment. Nit, but can you please ensure the line length remains reasonable (say < 80 characters) ? This can otherwise be annoying when reading/reviewing code.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, I'll fix it. I'm used to 120 chars line length...

@sunmy2019
Copy link
Member

We should get#106795 merged first to pass the test.

Comment on lines 300 to 301
runner = unittest.TextTestRunner()
runner.run(test_class('test_initializer'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Again, can you please instead put these checks directly inFailingInitializerMixin?
For example, add atearDown method:

deftearDown(self):super().tearDown()# shutdown executorifself.mp_contextandself.mp_context.get_start_method()in ("spawn","forkserver"):# Stop resource tracker manually now, so we can verify there are# not leaked resources by checking the process exit codefrommultiprocessing.resource_trackerimport_resource_tracker_resource_tracker._stop()self.assertEqual(_resource_tracker._exitcode,0)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@pitrou Checking

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Doesn't work

$ ./python -m unittest test.test_concurrent_futures.ProcessPoolForkserverFailingInitializerTest -vtest_initializer (test.test_concurrent_futures.ProcessPoolForkserverFailingInitializerTest.test_initializer) ... /home/user/cpython/Lib/multiprocessing/resource_tracker.py:236: UserWarning: resource_tracker: There appear to be 3 leaked semaphore objects to clean up at shutdown  warnings.warn('resource_tracker: There appear to be %d 'FAILTraceback (most recent call last):  File "/home/user/cpython/Lib/multiprocessing/util.py", line 300, in _run_finalizers    finalizer()  File "/home/user/cpython/Lib/multiprocessing/util.py", line 224, in __call__    res = self._callback(*self._args, **self._kwargs)          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/user/cpython/Lib/multiprocessing/synchronize.py", line 87, in _cleanup    sem_unlink(name)FileNotFoundError: [Errno 2] No such file or directoryTraceback (most recent call last):  File "/home/user/cpython/Lib/multiprocessing/util.py", line 300, in _run_finalizers    finalizer()  File "/home/user/cpython/Lib/multiprocessing/util.py", line 224, in __call__    res = self._callback(*self._args, **self._kwargs)          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/user/cpython/Lib/multiprocessing/synchronize.py", line 87, in _cleanup    sem_unlink(name)FileNotFoundError: [Errno 2] No such file or directoryTraceback (most recent call last):  File "/home/user/cpython/Lib/multiprocessing/util.py", line 300, in _run_finalizers    finalizer()  File "/home/user/cpython/Lib/multiprocessing/util.py", line 224, in __call__    res = self._callback(*self._args, **self._kwargs)          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/user/cpython/Lib/multiprocessing/synchronize.py", line 87, in _cleanup    sem_unlink(name)FileNotFoundError: [Errno 2] No such file or directory======================================================================FAIL: test_initializer (test.test_concurrent_futures.ProcessPoolForkserverFailingInitializerTest.test_initializer)----------------------------------------------------------------------Traceback (most recent call last):  File "/home/user/cpython/Lib/test/test_concurrent_futures.py", line 298, in tearDown    self.assertEqual(_resource_tracker._exitcode, 0)AssertionError: 1 != 0----------------------------------------------------------------------Ran 1 test in 0.269sFAILED (failures=1)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hmm, too bad :-(

@bityobbityob requested a review frompitrouJuly 23, 2023 14:47
@bityob
Copy link
ContributorAuthor

@pitrou
Hey,
Can you review again?
Thanks

@pitrou
Copy link
Member

@bityob Sorry for the delay. There were some recent changes in git main that are causing conflicts. Could you merge from main and fix the conflicts? Thank you!

…est_concurrent_futures.py) to new location (Lib/test/test_concurrent_futures/test_init.py)
…_futures-v2' of github.com:bityob/cpython intopythongh-104090-fix-leaked-semaphors-on-test_concurrent_futures-v2
@bityob
Copy link
ContributorAuthor

@bityob Sorry for the delay. There were some recent changes in git main that are causing conflicts. Could you merge from main and fix the conflicts? Thank you!

Hey@pitrou, Thank you!

I merged the main branch and resolved all conflicts.

Please review again

@pitroupitrou changed the titlegh-104090: Updated Resource Tracker to return exit code based on resource leaked found or notgh-104090: Update Resource Tracker to return exit code based on resource leaked found or notSep 19, 2023
Copy link
Member

@pitroupitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks@bityob for the update. LGTM now, let's wait for CI.

@pitrou
Copy link
Member

Unfortunately there are CI failures which look related. Can you take a look?

@bityob
Copy link
ContributorAuthor

Unfortunately there are CI failures which look related. Can you take a look?

Yes, thanks. I'll check

@encukou
Copy link
Member

I'd love to be able to tell whether ResourceTracker was successful, but testing it on the “live” global_resource_tracker interferes with other tests (or regrtest).
I'm planning to send a PR based on this one, which will test a fresh ResourceTracker instance.

encukou added a commit to encukou/cpython that referenced this pull requestFeb 13, 2024
…urceTracker instanceAdd a new 'dummy' resource, which has no side-effects whencleaned up.The ResourceTracker test then registers this 'dummy', and eitherunregisters it or not.
@encukou
Copy link
Member

My continuation of this PR is here:#115410

encukou added a commit that referenced this pull requestFeb 21, 2024
This builds on#106807, which addsa return code to ResourceTracker, to make future debugging easier.Testing this “in situ” proved difficult, since the global ResourceTracker isinvolved in test infrastructure. So, the tests here create a new instance andfeed it fake data.---------Co-authored-by: Yonatan Bitton <yonatan.bitton@perception-point.io>Co-authored-by: Yonatan Bitton <bityob@gmail.com>Co-authored-by: Antoine Pitrou <antoine@python.org>
@encukou
Copy link
Member

I've merged the continuation PR.
Thanks for doing the hard part!

auto-merge was automatically disabledFebruary 21, 2024 12:56

Pull request was closed

woodruffw pushed a commit to woodruffw-forks/cpython that referenced this pull requestMar 4, 2024
…thonGH-115410)This builds onpython#106807, which addsa return code to ResourceTracker, to make future debugging easier.Testing this “in situ” proved difficult, since the global ResourceTracker isinvolved in test infrastructure. So, the tests here create a new instance andfeed it fake data.---------Co-authored-by: Yonatan Bitton <yonatan.bitton@perception-point.io>Co-authored-by: Yonatan Bitton <bityob@gmail.com>Co-authored-by: Antoine Pitrou <antoine@python.org>
diegorusso pushed a commit to diegorusso/cpython that referenced this pull requestApr 17, 2024
…thonGH-115410)This builds onpython#106807, which addsa return code to ResourceTracker, to make future debugging easier.Testing this “in situ” proved difficult, since the global ResourceTracker isinvolved in test infrastructure. So, the tests here create a new instance andfeed it fake data.---------Co-authored-by: Yonatan Bitton <yonatan.bitton@perception-point.io>Co-authored-by: Yonatan Bitton <bityob@gmail.com>Co-authored-by: Antoine Pitrou <antoine@python.org>
LukasWoodtli pushed a commit to LukasWoodtli/cpython that referenced this pull requestJan 22, 2025
…thonGH-115410)This builds onpython#106807, which addsa return code to ResourceTracker, to make future debugging easier.Testing this “in situ” proved difficult, since the global ResourceTracker isinvolved in test infrastructure. So, the tests here create a new instance andfeed it fake data.---------Co-authored-by: Yonatan Bitton <yonatan.bitton@perception-point.io>Co-authored-by: Yonatan Bitton <bityob@gmail.com>Co-authored-by: Antoine Pitrou <antoine@python.org>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@iritkatrieliritkatrieliritkatriel left review comments

@pitroupitroupitrou approved these changes

@gpsheadgpsheadAwaiting requested review from gpsheadgpshead is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@bityob@bedevere-bot@sunmy2019@pitrou@encukou@iritkatriel

[8]ページ先頭

©2009-2025 Movatter.jp