8000 bpo-31356: Fixing PyErr_WarnEx might error out. by lisroach · Pull Request #5456 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-31356: Fixing PyErr_WarnEx might error out. #5456

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

Closed
wants to merge 1 commit into from

Conversation

lisroach
Copy link
Contributor
@lisroach lisroach commented Jan 31, 2018

Fixing a potential bug found by Yury, if for whatever reason raising the warning were to fail we need to catch that.

I am not entirely sure how to best test this- I am open to suggestions anyone has!

https://bugs.python.org/issue31356

@pablogsal
Copy link
Member
pablogsal commented Jan 31, 2018

@lisroach A possible test for this is repeat test_ensure_disabled_thread with warnings as errors:

warnings.filterwarnings('error')

and then checking for a RuntimeWarning exception instead of the warning. I think this will work because without the changes in this PR, this proposed test will produce this error:

======================================================================
ERROR: test_ensure_disabled_thread (Lib.test.test_gc.GCTogglingTests)
----------------------------------------------------------------------
RuntimeWarning: Garbage collector enabled while another thread is inside gc.ensure_enabled

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/pgalindo3/cpython/Lib/test/support/__init__.py", line 2083, in decorator
    return func(*args)
  File "/home/pgalindo3/cpython/Lib/test/test_gc.py", line 1063, in test_ensure_disabled_thread
    inside_status_after_thread = gc.isenabled()
SystemError: <built-in method __exit__ of gc.ensure_disabled object at 0x7f0253d22de0> returned a result with an error se

Another posible test is checking that SystemError is not raised / in stderr.

@@ -1068,8 +1068,10 @@ gc_enable_impl(PyObject *module)
/*[clinic end generated code: output=45a427e9dce9155c input=81ac4940ca579707]*/
{
if(_PyRuntime.gc.disabled_threads){
PyErr_WarnEx(PyExc_RuntimeWarning, "Garbage collector enabled while another "
"thread is inside gc.ensure_enabled",1);
if(PyErr_WarnEx(PyExc_RuntimeWarning, "Garbage collector enabled while another "
Copy link
Member

Choose a reason for hiding this comment

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

PEP 7: Add a space between if and the opening parenthesis. Fix also a line above.

PEP 7: The line is too long (88 columns). It would be better to split it after the first argument.

PyErr_WarnEx(PyExc_RuntimeWarning, "Garbage collector enabled while another "
"thread is inside gc.ensure_enabled",1);
if(PyErr_WarnEx(PyExc_RuntimeWarning, "Garbage collector enabled while another "
"thread is inside gc.ensure_enabled",1) == -1) {
Copy link
Member

Choose a reason for hiding this comment

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

PEP 7: Add a space after comma.

@@ -1068,8 +1068,10 @@ gc_enable_impl(PyObject *module)
/*[clinic end generated code: output=45a427e9dce9155c input=81ac4940ca579707]*/
{
if(_PyRuntime.gc.disabled_threads){
Copy link
Member

Choose a reason for hiding this comment

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

PEP 7: Add a space between the closing parenthesis and the opening brace.

"thread is inside gc.ensure_enabled",1);
if(PyErr_WarnEx(PyExc_RuntimeWarning, "Garbage collector enabled while another "
"thread is inside gc.ensure_enabled",1) == -1) {
PyErr_WriteUnraisable(module);
Copy link
Member

Choose a reason for hiding this comment

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

return NULL;

if(PyErr_WarnEx(PyExc_RuntimeWarning, "Garbage collector enabled while another "
"thread is inside gc.ensure_enabled",1) == -1) {
PyErr_WriteUnraisable(module);
}
Copy link
Member

Choose a reason for hiding this comment

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

This brace looks misaligned.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

PyErr_WarnEx(PyExc_RuntimeWarning, "Garbage collector enabled while another "
"thread is inside gc.ensure_enabled",1);
if(PyErr_WarnEx(PyExc_RuntimeWarning, "Garbage collector enabled while another "
"thread is inside gc.ensure_enabled",1) == -1) {
Copy link
Member

Choose a reason for hiding this comment

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

Since the condition is multiline, put the opening brace on a separate line.

@1st1
Copy link
Member
1st1 commented Jan 31, 2018

@serhiy-storchaka @lisroach I looked at the crash and there are multiple places in the code that need to be fixed that can't be directly commented on in this PR.

I'll open a new one.

@1st1 1st1 closed this Jan 31, 2018
@1st1
Copy link
Member
1st1 commented Jan 31, 2018

@lisroach Lisa, please review #5462. Sorry for closing this one, just trying to save some time to get this fixed and merged in beta-1.

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

Successfully merging this pull request may close these issues.

7 participants
0