traceback

Multiprocessing on Windows breaks

人走茶凉 提交于 2019-11-27 06:46:31
问题 I develop with Python on Linux and have never really seen this sort of problem with Windows. I'm using the multiprocessing library to speed up computations, which works very well for me on Linux. On Windows, however, things don't run as smoothly: * [INFO] Parsing 1 file using 2 threads Traceback (most recent call last): File "main.py", line 170, in <module> master = ParsingMaster(parser, list(input_file), output_list, threads=num_threads) Traceback (most recent call last): File "main.py",

How can I modify a Python traceback object when raising an exception?

感情迁移 提交于 2019-11-27 05:14:56
I'm working on a Python library used by third-party developers to write extensions for our core application. I'd like to know if it's possible to modify the traceback when raising exceptions, so the last stack frame is the call to the library function in the developer's code, rather than the line in the library that raised the exception. There are also a few frames at the bottom of the stack containing references to functions used when first loading the code that I'd ideally like to remove too. Thanks in advance for any advice! What about not changing the traceback? The two things you request

Error - input expected at most 1 argument, got 3

浪尽此生 提交于 2019-11-26 23:38:36
问题 I've set up the following for loop to accept 5 test scores. I want the loop to prompt the user to enter 5 different scores. Now I could do this by writing the input "Please enter your next test score", but I'd rather have each inputted score prompt for its associated number. So, for the first input, I'd like it to display "Please enter your score for test 1", and then for the second score, display "Please enter your score for test 2". When I try to run this loop, I get the following error:

How can I more easily suppress previous exceptions when I raise my own exception in response?

▼魔方 西西 提交于 2019-11-26 21:07:45
问题 Consider try: import someProprietaryModule except ImportError: raise ImportError('It appears that <someProprietaryModule> is not installed...') When run, if someProprietaryModule is not installed, one sees: (traceback data) ImportError: unknown module: someProprietaryModule During handling of the above exception, another exception occurred: (traceback data) ImportError: It appears that <someProprietaryModule> is not installed... Perhaps I don't want the "During handling of the above exception

How to exit from Python without traceback?

試著忘記壹切 提交于 2019-11-26 18:06:57
I would like to know how to I exit from Python without having an traceback dump on the output. I still want want to be able to return an error code but I do not want to display the traceback log. I want to be able to exit using exit(number) without trace but in case of an Exception (not an exit) I want the trace. jkp You are presumably encountering an exception and the program is exiting because of this (with a traceback). The first thing to do therefore is to catch that exception, before exiting cleanly (maybe with a message, example given). Try something like this in your main routine:

Get Traceback of warnings

限于喜欢 提交于 2019-11-26 17:58:46
问题 In numpy we can do np.seterr(invalid='raise') to get a traceback for warnings raising an error instead (see this post). Is there a general way for tracing warnings? Can I make python to give a traceback, when a warning is raised? 回答1: You can get what you want by assigning to warnings.showwarning . The warnings module documentation itself recommends that you do that, so it's not that you're being tempted by the dark side of the source . :) You may replace this function with an alternative

Python: Getting a traceback from a multiprocessing.Process

天大地大妈咪最大 提交于 2019-11-26 13:01:49
问题 I am trying to get hold of a traceback object from a multiprocessing.Process. Unfortunately passing the exception info through a pipe does not work because traceback objects can not be pickled: def foo(pipe_to_parent): try: raise Exception(\'xxx\') except: pipe_to_parent.send(sys.exc_info()) to_child, to_self = multiprocessing.Pipe() process = multiprocessing.Process(target = foo, args = (to_self,)) process.start() exc_info = to_child.recv() process.join() print traceback.format_exception(

Determine function name from within that function (without using traceback)

吃可爱长大的小学妹 提交于 2019-11-26 11:01:29
In Python, without using the traceback module, is there a way to determine a function's name from within that function? Say I have a module foo with a function bar. When executing foo.bar() , is there a way for bar to know bar's name? Or better yet, foo.bar 's name? #foo.py def bar(): print "my name is", __myname__ # <== how do I calculate this at runtime? Rosh Oxymoron Python doesn't have a feature to access the function or its name within the function itself. It has been proposed but rejected. If you don't want to play with the stack yourself, you should either use "bar" or bar.__name__

How to exit from Python without traceback?

守給你的承諾、 提交于 2019-11-26 06:13:42
问题 I would like to know how to I exit from Python without having an traceback dump on the output. I still want want to be able to return an error code but I do not want to display the traceback log. I want to be able to exit using exit(number) without trace but in case of an Exception (not an exit) I want the trace. 回答1: You are presumably encountering an exception and the program is exiting because of this (with a traceback). The first thing to do therefore is to catch that exception, before

Showing the stack trace from a running Python application

淺唱寂寞╮ 提交于 2019-11-26 03:17:41
问题 I have this Python application that gets stuck from time to time and I can\'t find out where. Is there any way to signal Python interpreter to show you the exact code that\'s running? Some kind of on-the-fly stacktrace? Related questions: Print current call stack from a method in Python code Check what a running process is doing: print stack trace of an uninstrumented Python program 回答1: I have module I use for situations like this - where a process will be running for a long time but gets