Skip to content
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

Intermittent test failure in test_subprocess.py:test_signals: SIGINT causes startup failure in child Python and unexpected return value #1170

Closed
njsmith opened this issue Aug 1, 2019 · 3 comments · Fixed by #1430

Comments

@njsmith
Copy link
Member

njsmith commented Aug 1, 2019

Observed here: https://dev.azure.com/python-trio/trio/_build/results?buildId=827&view=logs&jobId=300ae31b-e5d9-5bcb-b319-aee10d9d83f3

=================================== FAILURES ===================================
_________________________________ test_signals _________________________________

    async def test_signals():
        async def test_one_signal(send_it, signum):
            with move_on_after(1.0) as scope:
                async with await open_process(SLEEP(3600)) as proc:
                    send_it(proc)
            assert not scope.cancelled_caught
            if posix:
                assert proc.returncode == -signum
            else:
                assert proc.returncode != 0
    
        await test_one_signal(Process.kill, SIGKILL)
        await test_one_signal(Process.terminate, SIGTERM)
        if posix:
>           await test_one_signal(lambda proc: proc.send_signal(SIGINT), SIGINT)

/t/venv/lib/python3.7/site-packages/trio/tests/test_subprocess.py:366: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

send_it = <function test_signals.<locals>.<lambda> at 0x7f7e2d578840>
signum = <Signals.SIGINT: 2>

    async def test_one_signal(send_it, signum):
        with move_on_after(1.0) as scope:
            async with await open_process(SLEEP(3600)) as proc:
                send_it(proc)
        assert not scope.cancelled_caught
        if posix:
>           assert proc.returncode == -signum
E           assert -6 == -2
E             --6
E             +-2

/t/venv/lib/python3.7/site-packages/trio/tests/test_subprocess.py:359: AssertionError
----------------------------- Captured stderr call -----------------------------
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Traceback (most recent call last):
  File "/t/venv/lib/python3.7/encodings/latin_1.py", line 13, in <module>
    class Codec(codecs.Codec):
KeyboardInterrupt

In this test we're sending SIGINT to a child process, and the child process happens to be Python, and apparently Python's startup logic is flaky if a SIGINT arrives at the wrong time.

I think the simplest fix would be to make the test use a different signal, one that Python doesn't catch? Maybe SIGKILL + SIGTERM, if we're worried about making sure that send_signal isn't accidentally doing the same thing as kill or terminate?

@njsmith
Copy link
Member Author

njsmith commented Jan 31, 2020

Seen again on Linux Python 3.6 in Azure Pipelines: https://dev.azure.com/python-trio/trio/_build/results?buildId=1461&view=logs&jobId=9a864fd9-6c8f-52ca-79ce-2aa6dca1a1de&j=9a864fd9-6c8f-52ca-79ce-2aa6dca1a1de&t=14435553-4bd6-5ab0-e7af-caf830f382a2

_________________________________ test_signals _________________________________

    async def test_signals():
        async def test_one_signal(send_it, signum):
        await test_one_signal(Process.terminate, SIGTERM)
        if posix:
>           await test_one_signal(lambda proc: proc.send_signal(SIGINT), SIGINT)

/opt/hostedtoolcache/Python/3.6.10/x64/lib/python3.6/site-packages/trio/tests/test_subprocess.py:366: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

send_it = <function test_signals.<locals>.<lambda> at 0x7f57d234a730>
signum = <Signals.SIGINT: 2>

    async def test_one_signal(send_it, signum):
        with move_on_after(1.0) as scope:
            async with await open_process(SLEEP(3600)) as proc:
                send_it(proc)
        assert not scope.cancelled_caught
        if posix:
>           assert proc.returncode == -signum
E           assert 1 == -2
E             -1
E             +-2

/opt/hostedtoolcache/Python/3.6.10/x64/lib/python3.6/site-packages/trio/tests/test_subprocess.py:359: AssertionError
----------------------------- Captured stderr call -----------------------------
Failed to import the site module
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.6.10/x64/lib/python3.6/site.py", line 73, in <module>
    import os
  File "/opt/hostedtoolcache/Python/3.6.10/x64/lib/python3.6/os.py", line 57, in <module>
    import posixpath as path
  File "/opt/hostedtoolcache/Python/3.6.10/x64/lib/python3.6/posixpath.py", line 28, in <module>
    import genericpath
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 674, in exec_module
  File "<frozen importlib._bootstrap_external>", line 779, in get_code
  File "<frozen importlib._bootstrap_external>", line 487, in _compile_bytecode
KeyboardInterrupt

Originally posted by @pquentin in #851 (comment)

@njsmith njsmith changed the title Intermittent test failure in test_subprocess.py: "can't initialize sys standard streams" Intermittent test failure in test_subprocess.py:test_signals: SIGINT causes startup failure in child Python and unexpected return value Jan 31, 2020
@pquentin
Copy link
Member

I just noticed the note in #200 that mentions that we should select "Retain log" on Azure Pipelines. However I only see "Toggle timestamps".

Capture d’écran 2020-01-31 à 14 17 20

@njsmith
Copy link
Member Author

njsmith commented Jan 31, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants