Skip to content

gh-109582: test_fork_signal_handling should wait for event #109605

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2023

Conversation

sorcio
Copy link
Contributor

@sorcio sorcio commented Sep 20, 2023

Sometimes the child_handled event was missing because either the child quits before it gets a chance to handle the signal, or the parent asserts before the event notification is delivered via IPC. Synchronize explicitly to avoid this.

@sorcio
Copy link
Contributor Author

sorcio commented Sep 20, 2023

Does this need a changelog entry? The failing test was introduced in 3.12.

@gvanrossum
Copy link
Member

Does this need a changelog entry? The failing test was introduced in 3.12.

No, because it's just a test fix.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

@@ -1911,8 +1913,14 @@ def test_fork_signal_handling(self):
parent_handled = manager.Event()

Copy link
Member

Choose a reason for hiding this comment

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

I didn't know that another test_asyncio test uses multiprocessing.

It might be interesting to call from multiprocessing.util._cleanup_tests() in this test file as well: see commit 09ea4b8 and gh-109295.

But this one is less important since it doesn't pull most heavy multiprocessing resources, it's "just" a fork manager :-)

child_started.set()
while True:
time.sleep(1)
Copy link
Member

Choose a reason for hiding this comment

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

It took me a while to understand that the child doesn't run the loop forever, but is interrupted by SIGTERM and so exits immediately.

@@ -1933,6 +1941,7 @@ async def func():

asyncio.run(main())

child_handled.wait(timeout=support.SHORT_TIMEOUT)
Copy link
Member

Choose a reason for hiding this comment

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

Right, that's a good way to synchronize the parent and the child.

@vstinner
Copy link
Member

Merged thanks. I copied your rationale in the commit message. IMO it's important to keep it.

@vstinner vstinner added the needs backport to 3.12 only security fixes label Sep 21, 2023
@miss-islington
Copy link
Contributor

Thanks @sorcio for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 21, 2023
…honGH-109605)

Sometimes the child_handled event was missing because either
the child quits before it gets a chance to handle the signal,
or the parent asserts before the event notification is
delivered via IPC.  Synchronize explicitly to avoid this.
(cherry picked from commit 608c1f3)

Co-authored-by: Davide Rizzo <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Sep 21, 2023

GH-109695 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Sep 21, 2023
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot s390x Debian 3.x has failed when building commit 608c1f3.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/49/builds/6625) and take a look at the build logs.
  4. Check if the failure is related to this commit (608c1f3) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/49/builds/6625

Failed tests:

  • test_tools

Failed subtests:

  • test_freeze_simple_script - test.test_tools.test_freeze.TestFreeze.test_freeze_simple_script

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/dje/cpython-buildarea/3.x.edelsohn-debian-z/build/Lib/test/test_tools/test_freeze.py", line 32, in test_freeze_simple_script
    outdir, scriptfile, python = helper.prepare(script, outdir)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dje/cpython-buildarea/3.x.edelsohn-debian-z/build/Tools/freeze/test/freeze.py", line 146, in prepare
    copy_source_tree(srcdir, SRCDIR)
  File "/home/dje/cpython-buildarea/3.x.edelsohn-debian-z/build/Tools/freeze/test/freeze.py", line 95, in copy_source_tree
    shutil.copytree(oldroot, newroot, ignore=ignore_non_src)
  File "/home/dje/cpython-buildarea/3.x.edelsohn-debian-z/build/Lib/shutil.py", line 588, in copytree
    return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dje/cpython-buildarea/3.x.edelsohn-debian-z/build/Lib/shutil.py", line 542, in _copytree
    raise Error(errors)
shutil.Error: [('/home/dje/cpython-buildarea/3.x.edelsohn-debian-z/build/build/test_python_4007653æ/@test_4007653_tmpæ-tardir/extractall_ctrl/ustar/fifotype', '/tmp/test_python__vtyw1hx/tmp45g1m7z4/cpython/build/test_python_4007653æ/@test_4007653_tmpæ-tardir/extractall_ctrl/ustar/fifotype', '`/home/dje/cpython-buildarea/3.x.edelsohn-debian-z/build/build/test_python_4007653æ/@test_4007653_tmpæ-tardir/extractall_ctrl/ustar/fifotype` is a named pipe')]

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot s390x Fedora 3.x has failed when building commit 608c1f3.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/223/builds/4511) and take a look at the build logs.
  4. Check if the failure is related to this commit (608c1f3) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/223/builds/4511

Failed tests:

  • test.test_concurrent_futures.test_as_completed

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/dje/cpython-buildarea/3.x.edelsohn-fedora-z/build/Lib/test/test_concurrent_futures/test_as_completed.py", line 60, in test_future_times_out
    self.assertEqual(completed_futures, already_completed)
AssertionError: Items in the first set but not the second:
<Future at 0x3ff9280f1c0 state=finished returned NoneType>

@sorcio sorcio deleted the fix/test-asyncio-fork-signal branch September 22, 2023 12:44
csm10495 pushed a commit to csm10495/cpython that referenced this pull request Sep 28, 2023
…hon#109605)

Sometimes the child_handled event was missing because either
the child quits before it gets a chance to handle the signal,
or the parent asserts before the event notification is
delivered via IPC.  Synchronize explicitly to avoid this.
Yhg1s pushed a commit that referenced this pull request Oct 2, 2023
…-109605) (#109695)

gh-109582: test_fork_signal_handling should wait for event (GH-109605)

Sometimes the child_handled event was missing because either
the child quits before it gets a chance to handle the signal,
or the parent asserts before the event notification is
delivered via IPC.  Synchronize explicitly to avoid this.
(cherry picked from commit 608c1f3)

Co-authored-by: Davide Rizzo <[email protected]>
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…hon#109605)

Sometimes the child_handled event was missing because either
the child quits before it gets a chance to handle the signal,
or the parent asserts before the event notification is
delivered via IPC.  Synchronize explicitly to avoid this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants