[issue1230540] sys.excepthook doesn't work in threads

2019-05-28 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: If we want to support low-level threads created by start_new_thread() we should call excepthook() from t_bootstrap instead of Thread._bootstrap_inner. Otherwise implementing excepthook() as a Thread method would be more convenient. --

[issue1230540] sys.excepthook doesn't work in threads

2019-05-27 Thread STINNER Victor
STINNER Victor added the comment: It took 14 years, but this issue is now fixed ;-) I close it. Python 3.8 beta 1 will be released in a few days with threading.excepthook(): please test it to ensure that it works as you expected. As a follow-up, I created bpo-37069: "regrtest: log

[issue1230540] sys.excepthook doesn't work in threads

2019-05-27 Thread STINNER Victor
STINNER Victor added the comment: New changeset cd590a7cede156a4244e7cac61e4504e5344d842 by Victor Stinner in branch 'master': bpo-1230540: Add threading.excepthook() (GH-13515) https://github.com/python/cpython/commit/cd590a7cede156a4244e7cac61e4504e5344d842 --

[issue1230540] sys.excepthook doesn't work in threads

2019-05-25 Thread STINNER Victor
STINNER Victor added the comment: > In any case, I think the namedtuple / structseq solution is elegant, because > we can add additional information later I used the same design for the new sys.unraisablehook in bpo-36829 and I'm already working on adding a new 'err_msg' field to the

[issue1230540] sys.excepthook doesn't work in threads

2019-05-25 Thread STINNER Victor
STINNER Victor added the comment: Antoine Pitrou: > A Thread.excepthook() method does not allow to notify exceptions raised in > C-created threads ("dummy threads"). I modified my PR to use the threading identitifer (threading.get_ident()) as the thread name if args.thread is None.

[issue1230540] sys.excepthook doesn't work in threads

2019-05-25 Thread STINNER Victor
STINNER Victor added the comment: > Indeed, if you write your own Thread class, you can add a try...except > in the Thread.run() method. You don't need a dedicated > Thread.excepthook() method. Exactly. You can already do you best in your run() method to handle exceptions.

[issue1230540] sys.excepthook doesn't work in threads

2019-05-25 Thread Antoine Pitrou
Antoine Pitrou added the comment: Le 25/05/2019 à 23:09, STINNER Victor a écrit : > > I don't see the relationship between the API (signature) and the ability to > set a per-thread hook. > > I'm not convinced that a per-thread hook is needed. Indeed, if you write your own Thread class, you

[issue1230540] sys.excepthook doesn't work in threads

2019-05-25 Thread Antoine Pitrou
Antoine Pitrou added the comment: Sorry, I had overlooked the issue with global variables at shutdown. Though that issue only occurs with daemonic threads, since non-daemonic threads are joined before global variables are cleared. In any case, I think the namedtuple / structseq solution is

[issue1230540] sys.excepthook doesn't work in threads

2019-05-25 Thread STINNER Victor
STINNER Victor added the comment: Serhiy Storchaka: > I propose to add the Thead.excepthook() method with the signature compatible > with sys.excepthook(). This will allow to set easily per-thread hooks and a > global hook. I don't see the relationship between the API (signature) and the

[issue1230540] sys.excepthook doesn't work in threads

2019-05-25 Thread STINNER Victor
STINNER Victor added the comment: > A Thread.excepthook() method does not allow to notify exceptions raised in > C-created threads ("dummy threads"). The main difference between sys.excepthook and threading.excepthook is that the threading hook displays the thread name. Which output do you

[issue1230540] sys.excepthook doesn't work in threads

2019-05-25 Thread Antoine Pitrou
Antoine Pitrou added the comment: A Thread.excepthook() method does not allow to notify exceptions raised in C-created threads ("dummy threads"). Also, as I said already, you can get the current thread by calling threading.current_thread() in the except hook. There is no need to pass it

[issue1230540] sys.excepthook doesn't work in threads

2019-05-25 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I propose to add the Thead.excepthook() method with the signature compatible with sys.excepthook(). This will allow to set easily per-thread hooks and a global hook. -- nosy: +serhiy.storchaka ___ Python

[issue1230540] sys.excepthook doesn't work in threads

2019-05-24 Thread STINNER Victor
STINNER Victor added the comment: If you want to reuse sys.excepthook to handle uncaught Thread.run() exception, you can now write: --- def hook(args): if args.exc_type == SystemExit: return sys.excepthook(args.exc_type, args.exc_value, args.exc_traceback)

[issue1230540] sys.excepthook doesn't work in threads

2019-05-24 Thread STINNER Victor
STINNER Victor added the comment: I rewrote my PR 13515: * threading.excepthook() now gets a single argument which has multiple attributes: (exc_type, exc_value, exc_traceback, thread) * The default threading.excepthook() implementation in written in C which reduces the risk of missing

[issue1230540] sys.excepthook doesn't work in threads

2019-05-23 Thread STINNER Victor
STINNER Victor added the comment: There is a special case. If a thread calls os.fork() and Thread.run() raises an exception, the thread name is still logged even if there is only 1 thread after fork. Try attached fork_thread.py. Output on Python 3.7: --- main thread: spawn fork thread

[issue1230540] sys.excepthook doesn't work in threads

2019-05-23 Thread Antoine Pitrou
Antoine Pitrou added the comment: > Moreover, when sys.excepthook is called, the hook doesn't get access to the > thread object You can get it with threading.current_thread(), no? -- ___ Python tracker

[issue1230540] sys.excepthook doesn't work in threads

2019-05-22 Thread Christoph Reiter
Christoph Reiter added the comment: > Let's say that in Python 3.8 threading.Thread now calls sys.execpthook() to > handle uncaught run() exception. All applications which override > sys.excepthook() on purpose will behave differently: start to log exceptions > from threads. But existing

[issue1230540] sys.excepthook doesn't work in threads

2019-05-22 Thread STINNER Victor
STINNER Victor added the comment: About threading.excepthook() API, maybe we should not reproduce sys.excepthook() API but instead reuse something closer to sys.unraisablehook() API: use a single parameter which has attributes. It would allow to pass more parameters as new attributes in the

[issue1230540] sys.excepthook doesn't work in threads

2019-05-22 Thread STINNER Victor
STINNER Victor added the comment: I dislike PR 8610: threading.Thread doesn't call sys.excepthook to handle run() exception by default, it only calls sys.excepthook if it's overridden. Moreover, when sys.excepthook is called, the hook doesn't get access to the thread object :-( --

[issue1230540] sys.excepthook doesn't work in threads

2019-05-22 Thread STINNER Victor
STINNER Victor added the comment: I wrote PR 13515 which adds threading.excepthook(). I chose to call threading.excepthook() even when run() raises SystemExit. In this case, threading.excepthook() simply does nothing. The idea is to really give the full control when threading.excepthook()

[issue1230540] sys.excepthook doesn't work in threads

2019-05-22 Thread STINNER Victor
Change by STINNER Victor : -- pull_requests: +13432 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue1230540] sys.excepthook doesn't work in threads

2019-05-22 Thread STINNER Victor
STINNER Victor added the comment: See also bpo-36829: I just added sys.unraisablehook(). -- ___ Python tracker ___ ___

[issue1230540] sys.excepthook doesn't work in threads

2018-08-31 Thread Christoph Reiter
Christoph Reiter added the comment: To add one more use case for this: concurrent.futures.Future.add_done_callback() currently ignores exceptions for the callback and just logs them which is easy to miss. I assume because it's not clear when and in which thread it gets called, and there is

[issue1230540] sys.excepthook doesn't work in threads

2018-08-31 Thread STINNER Victor
STINNER Victor added the comment: My concern is more about backward compatibility. Documentation is one thing, but usually users rely on the actual implementation, not on the documentation, to define what is the Python behaviour. Would you mind to open a thread on python-dev about this

[issue1230540] sys.excepthook doesn't work in threads

2018-08-04 Thread Andrey Vlasovskikh
Andrey Vlasovskikh added the comment: > Would it be possible to modify the default implementation of sys.excepthook > to have a different output when it's not called from the main thread? Mimick > the current traceback from threads. I agree it's a good idea to mimic what `_thread` does in

[issue1230540] sys.excepthook doesn't work in threads

2018-08-02 Thread Nikolaus Rath
Change by Nikolaus Rath : -- nosy: -nikratio ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue1230540] sys.excepthook doesn't work in threads

2018-08-02 Thread STINNER Victor
STINNER Victor added the comment: Would it be possible to modify the default implementation of sys.excepthook to have a different output when it's not called from the main thread? Mimick the current traceback from threads. Would it be possible to call threading.current_thread() from the

[issue1230540] sys.excepthook doesn't work in threads

2018-08-01 Thread Antoine Pitrou
Antoine Pitrou added the comment: No, I think this is a bug that deserves fixing, at least in 3.8. -- versions: +Python 3.8 -Python 2.7, Python 3.5, Python 3.6, Python 3.7 ___ Python tracker

[issue1230540] sys.excepthook doesn't work in threads

2018-08-01 Thread Andrey Vlasovskikh
Andrey Vlasovskikh added the comment: I've added a PR with a patch I developed during the EuroPython 2018 sprint. I've fixed this issue in a way that is more or less consistent with how '_thread' threads interact with sys.excepthook, but I haven't added the log line they print to sys.stderr

[issue1230540] sys.excepthook doesn't work in threads

2018-08-01 Thread Andrey Vlasovskikh
Change by Andrey Vlasovskikh : -- keywords: +patch pull_requests: +8116 stage: needs patch -> patch review ___ Python tracker ___

[issue1230540] sys.excepthook doesn't work in threads

2018-04-08 Thread Nick Coghlan
Change by Nick Coghlan : -- nosy: +ncoghlan ___ Python tracker ___ ___

[issue1230540] sys.excepthook doesn't work in threads

2017-09-20 Thread Antoine Pitrou
Antoine Pitrou added the comment: Matt, do you want to post your patch here? -- ___ Python tracker ___ ___

[issue1230540] sys.excepthook doesn't work in threads

2017-09-15 Thread Matt Groth
Matt Groth added the comment: Thank you Antoine Pitrou, I was able to disable this behavior by commenting out some lines of code in 'traceback' and replacing them with the appropriate call to 'sys.excepthook'. Note you also have to comment out a few lines in "Modules/_threadmodule.c" to

[issue1230540] sys.excepthook doesn't work in threads

2017-06-28 Thread Antoine Pitrou
Antoine Pitrou added the comment: Apparently the `traceback` module has been used from the start (since changset 7f5013a9a9678e86bff00c97f98e7a92c515b94d) to print the exception and not sys.excepthook. I presume this is an oversight, as I don't see any reason to prefer `traceback` here.

[issue1230540] sys.excepthook doesn't work in threads

2017-02-24 Thread CyberJacob
CyberJacob added the comment: Just confirmed, this does affect multiprocessing. script to reproduce: import sys, multiprocessing def log_exception(*args): print 'got exception %s' % (args,) sys.excepthook = log_exception def foo(): a = 1 / 0

[issue1230540] sys.excepthook doesn't work in threads

2017-02-24 Thread Jacob Mansfield
Jacob Mansfield added the comment: Does this affect threads started with the multiprocessing library as well? -- nosy: +Jacob Mansfield ___ Python tracker

[issue1230540] sys.excepthook doesn't work in threads

2016-08-04 Thread Decorater
Decorater added the comment: Ok, so I just found out you can bypass thread exceptions by wraping the line that actually runs the threads in a try/except block and then using the logging module to log it to a file instead of the console. -- ___

[issue1230540] sys.excepthook doesn't work in threads

2016-08-04 Thread Decorater
Decorater added the comment: personally these exceptions in console can be annoying to me as I hate seeing them. Exception in thread Thread-11: Traceback (most recent call last): File "threading.py", line 914, in _bootstrap_inner File

[issue1230540] sys.excepthook doesn't work in threads

2016-08-04 Thread Decorater
Decorater added the comment: I too agree that I hate the thread exceptions being printed in the console I would suggest python was to error log it all to a file instead (so it does not spam up the console). I get it a lot with websocket / opus errors and it is annoying because it does not

[issue1230540] sys.excepthook doesn't work in threads

2011-09-11 Thread Nikolaus Rath
Changes by Nikolaus Rath nikol...@rath.org: -- nosy: +Nikratio ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1230540 ___ ___ Python-bugs-list

[issue1230540] sys.excepthook doesn't work in threads

2010-08-03 Thread Terry J. Reedy
Changes by Terry J. Reedy tjre...@udel.edu: -- stage: - unit test needed versions: +Python 2.7, Python 3.2 -Python 2.5, Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1230540 ___

[issue1230540] sys.excepthook doesn't work in threads

2009-08-03 Thread Ian Beaver
Ian Beaver undercoverid...@gmail.com added the comment: I found that the workaround suggested doesn't work when you have a subclass of threading.Thread and you want to catch everything in the module that contains the class to a common log. Say you have a module with a socket server that spawns

[issue1230540] sys.excepthook doesn't work in threads

2009-08-03 Thread Ian Beaver
Ian Beaver undercoverid...@gmail.com added the comment: Instead of using decorators, this is a slightly simpler modification to the proposed workaround that allows for any subclassed run method to also be caught. def installThreadExcepthook(): Workaround for sys.excepthook thread bug

[issue1230540] sys.excepthook doesn't work in threads

2008-02-24 Thread Tiago Alves
Tiago Alves added the comment: I don't see it as a problem or as the threading module trying to be clever. It clearly was a design choice to make the module have its own exception treatment in order to make it clear in which thread the exception occurred. IMHO the decision here should be to

[issue1230540] sys.excepthook doesn't work in threads

2007-11-23 Thread Christian Heimes
Changes by Christian Heimes: -- versions: +Python 2.5, Python 2.6 -Python 2.4 _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1230540 _ ___ Python-bugs-list