[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-28 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset a85a1d337d26a65036e427341d15e3979f7e9ced by Victor Stinner in 
branch 'master':
bpo-36829: sys.excepthook and sys.unraisablehook flush (GH-13620)
https://github.com/python/cpython/commit/a85a1d337d26a65036e427341d15e3979f7e9ced


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-28 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +13521
pull_request: https://github.com/python/cpython/pull/13620

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-27 Thread STINNER Victor


STINNER Victor  added the comment:

Ok, the initial issue has been fixed by adding a new sys.unraisablehook() 
function. You can kill the process with SIGABRT using the recipe I proposed 
there:
https://bugs.python.org/issue36829#msg343201

As a follow-up, I created bpo-37069: "regrtest: log unraisable exceptions and 
uncaught thread exceptions".

Thanks Thomas Grainger for reviews and for reporting this interesting issue ;-)

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-27 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 71c52e3048dd07567f0c690eab4e5d57be66f534 by Victor Stinner in 
branch 'master':
bpo-36829: Add _PyErr_WriteUnraisableMsg() (GH-13488)
https://github.com/python/cpython/commit/71c52e3048dd07567f0c690eab4e5d57be66f534


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-24 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 6dbbe748e101a173b4cff8aada41e9313e287e0f by Victor Stinner in 
branch 'master':
bpo-36829: Document test.support.catch_unraisable_exception() (GH-13554)
https://github.com/python/cpython/commit/6dbbe748e101a173b4cff8aada41e9313e287e0f


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-24 Thread STINNER Victor


STINNER Victor  added the comment:

> Could test.support.catch_unraisable_exception also be documented at 
> https://docs.python.org/3/library/test.html#module-test.support ?

I wrote PR 13554 to document it.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-24 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +13465

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-23 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Could test.support.catch_unraisable_exception also be documented at 
https://docs.python.org/3/library/test.html#module-test.support ?

--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-22 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset df22c03b93ea4620fdf4a0b3cbbbfa7c645af783 by Victor Stinner in 
branch 'master':
bpo-36829: PyErr_WriteUnraisable() normalizes exception (GH-13507)
https://github.com/python/cpython/commit/df22c03b93ea4620fdf4a0b3cbbbfa7c645af783


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-22 Thread STINNER Victor


STINNER Victor  added the comment:

See also bpo-1230540: "sys.excepthook doesn't work in threads".

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-22 Thread STINNER Victor


STINNER Victor  added the comment:

I wrote PR 13512 to use support.catch_unraisable_exception() in 
test_io.test_error_through_destructor(). But this PR is associated to bpo-18748 
since the main change is related to the io module, not sys.unraisablehook ;-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-22 Thread STINNER Victor


STINNER Victor  added the comment:

In PR 13490, Thomas Grainger proposed a cool context manager:

@contextlib.contextmanager
def throw_unraisable_exceptions():
unraisable = None
old_hook = sys.unraisablehook

def hook(exc):
nonlocal unraisable
unraisable = exc

sys.unraisablehook = hook
try:
yield
if unraisable is not None:
raise unraisable
finally:
unraisable = None
sys.unraisablehook = old_hook

It allows to raise an unraisable exception :-D Example:

try:
with support.throw_unraisable_exceptions():
...
except Exception as e:
... # the exception is now here

I don't need such context manager right now, but I like the fact that it 
becomes possible to write such context manager :-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-22 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset e4d300e07c33a9a77549c62d8687d8fe130c53d5 by Victor Stinner in 
branch 'master':
bpo-36829: Add test.support.catch_unraisable_exception() (GH-13490)
https://github.com/python/cpython/commit/e4d300e07c33a9a77549c62d8687d8fe130c53d5


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-22 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +13423

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-22 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset a58db9628d0c96cc5b863137fed4e432238f8027 by Victor Stinner in 
branch '3.7':
bpo-36829: Enhance PyErr_WriteUnraisable() (GH-13487)
https://github.com/python/cpython/commit/a58db9628d0c96cc5b863137fed4e432238f8027


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-22 Thread STINNER Victor


STINNER Victor  added the comment:

I merged my PR #13187, so I reject PR #13175.

In the python-dev thread, there is no consensus in favor of -X abortunraisable 
option. The few people who pronounce them on this option were more against it.
https://mail.python.org/pipermail/python-dev/2019-May/157436.html

At least, you can now very easily reimplement it in a few line of pure Python 
using the new sys.unraisablehook! For example, add this code to Lib/site.py:
---
if 'abortunraisable' in sys._xoptions:
import signal
def abort_hook(unraisable,
   # keep a reference to continue to work
   # during Python shutdown
   raise_signal=signal.raise_signal,
   SIGABRT=signal.SIGABRT):
raise_signal(SIGABRT)
sys.unraisablehook = abort_hook
---

Example with attached gc_callback.py:
---
$ ./python -X dev gc_callback.py 
Exception ignored in: 
Traceback (most recent call last):
  File "gc_callback.py", line 7, in wr_callback
raise ValueError(42)
ValueError: 42

$ ./python -X abortunraisable gc_callback.py 
Aborted (core dumped)

$ ./python -X abortunraisable -X faulthandler gc_callback.py 
Fatal Python error: Aborted

Current thread 0x7fed6edc7740 (most recent call first):
  File "/home/vstinner/prog/python/master/Lib/site.py", line 649 in abort_hook
  File "gc_callback.py", line 11 in 
Aborted (core dumped)
---

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-22 Thread STINNER Victor


STINNER Victor  added the comment:

Follow-up:

* PR 13487 backports enhancement and bugfix to Python 3.7
* PR 13488 adds _PyErr_WriteUnraisableMsg() and adds 'err_msg' field to 
sys.unraisablehook
* PR 13490 adds test.support.catch_unraisable_exception()

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-22 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +13406

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-22 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +13404

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-22 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +13403

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-22 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset ef9d9b63129a2f243591db70e9a2dd53fab95d86 by Victor Stinner in 
branch 'master':
bpo-36829: Add sys.unraisablehook() (GH-13187)
https://github.com/python/cpython/commit/ef9d9b63129a2f243591db70e9a2dd53fab95d86


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-15 Thread STINNER Victor


STINNER Victor  added the comment:

I started a thread on python-dev to discuss the issue:
https://mail.python.org/pipermail/python-dev/2019-May/157436.html

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-14 Thread STINNER Victor


STINNER Victor  added the comment:

I'm interested to modify regrtest (test runner of the Python test suite) to use 
sys.unraisablehook(). It would be nice to add an option to display again *all* 
unraisable exceptions in the test summary, at the end.

I did a similar experimentation for any warnings, so my implementation was 
fragile because regrtest was hard to extend. That's why I introduced a new 
TestResult type: to be able to add more fields without breaking all the code. 
Prevously, a test result was a tuple which was manually unpacked. So adding a 
new field could break code which wasn't updated to handle new fields.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

2019-05-14 Thread STINNER Victor


Change by STINNER Victor :


--
title: CLI option to make PyErr_WriteUnraisable abort the current process -> 
Add sys.unraisablehook() to custom how "unraisable exceptions" are logged

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com