Skip to content

Comments

bpo-40826: Add _PyOS_InterruptOccurred(tstate) function#20599

Merged
vstinner merged 3 commits intopython:masterfrom
vstinner:interrupt_tstate
Jun 3, 2020
Merged

bpo-40826: Add _PyOS_InterruptOccurred(tstate) function#20599
vstinner merged 3 commits intopython:masterfrom
vstinner:interrupt_tstate

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Jun 2, 2020

my_fgets() now calls _PyOS_InterruptOccurred(tstate) to check for
pending signals, rather calling PyOS_InterruptOccurred().

my_fgets() is called with the GIL released, whereas
PyOS_InterruptOccurred() must be called with the GIL held.

https://bugs.python.org/issue40826

my_fgets() now calls _PyOS_InterruptOccurred(tstate) to check for
pending signals, rather calling PyOS_InterruptOccurred().

my_fgets() is called with the GIL released, whereas
PyOS_InterruptOccurred() must be called with the GIL held.
@vstinner
Copy link
Member Author

vstinner commented Jun 2, 2020

@corona10: Ok here my fix for https://bugs.python.org/issue40826 Should I include the test that you wrote in PR #20549?

@corona10
Copy link
Member

corona10 commented Jun 2, 2020

@vstinner Please go ahead :)

test_repl: use text=True and avoid SuppressCrashReport in
test_multiline_string_parsing().
@vstinner
Copy link
Member Author

vstinner commented Jun 2, 2020

Well, I added a test, but different than yours.

@vstinner
Copy link
Member Author

vstinner commented Jun 2, 2020

The test fails on Windows:

FAIL: test_close_stdin (test.test_repl.TestInteractiveInterpreter)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\cpython\cpython\lib\test\test_repl.py", line 103, in test_close_stdin
    self.assertEqual(process.returncode, 0)
AssertionError: 3221226505 != 0

@corona10
Copy link
Member

corona10 commented Jun 2, 2020

The test fails on Windows:

Yeah, I skipped the test on Windows.

@vstinner
Copy link
Member Author

vstinner commented Jun 2, 2020

Yeah, I skipped the test on Windows.

Well, 3221226505 exit code is STATUS_STACK_BUFFER_OVERRUN (0xC0000409): it's a crash.

It seems like fgets() crash when the file descriptor is closed.

On Windows, fgets(fp) does crash if fileno(fp) is closed.
@vstinner
Copy link
Member Author

vstinner commented Jun 2, 2020

@corona10: I fixed yet another bug, crash on Windows, in my PR. Would you mind to review the PR?

Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

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

Nice! LGTM

The PR is very awesome that it solve also the Windows issue :)

@vstinner vstinner merged commit fa7ab6a into python:master Jun 3, 2020
@vstinner vstinner deleted the interrupt_tstate branch June 3, 2020 12:40
@vstinner
Copy link
Member Author

vstinner commented Jun 3, 2020

Thanks for the review @corona10.

vstinner added a commit that referenced this pull request Jun 3, 2020
* bpo-40826: Fix GIL usage in PyOS_Readline() (GH-20579)

Fix GIL usage in PyOS_Readline(): lock the GIL to set an exception.

Pass tstate to my_fgets() and _PyOS_WindowsConsoleReadline(). Cleanup
these functions.

(cherry picked from commit c353764)

* bpo-40826: Add _PyOS_InterruptOccurred(tstate) function (GH-20599)

my_fgets() now calls _PyOS_InterruptOccurred(tstate) to check for
pending signals, rather calling PyOS_InterruptOccurred().

my_fgets() is called with the GIL released, whereas
PyOS_InterruptOccurred() must be called with the GIL held.

test_repl: use text=True and avoid SuppressCrashReport in
test_multiline_string_parsing().

Fix my_fgets() on Windows: fgets(fp) does crash if fileno(fp) is closed.

(cherry picked from commit fa7ab6a)
vstinner added a commit that referenced this pull request Jun 3, 2020
* bpo-40826: Fix GIL usage in PyOS_Readline() (GH-20579)

Fix GIL usage in PyOS_Readline(): lock the GIL to set an exception.

Pass tstate to my_fgets() and _PyOS_WindowsConsoleReadline(). Cleanup
these functions.

(cherry picked from commit c353764)

* bpo-40826: Add _PyOS_InterruptOccurred(tstate) function (GH-20599)

my_fgets() now calls _PyOS_InterruptOccurred(tstate) to check for
pending signals, rather calling PyOS_InterruptOccurred().

my_fgets() is called with the GIL released, whereas
PyOS_InterruptOccurred() must be called with the GIL held.

test_repl: use text=True and avoid SuppressCrashReport in
test_multiline_string_parsing().

Fix my_fgets() on Windows: fgets(fp) does crash if fileno(fp) is closed.

(cherry picked from commit fa7ab6a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants