exception-handling

Why does Celery NOT throw an Exception when the underlying task throws one

Why does Celery NOT throw an Exception when the underlying task throws one Question: Celery doesn’t seem to be handling exceptions properly. If I have task: def errorTest(): raise Exception() and then I call r = errorTest.delay() In [8]: r.result In [9]: r.state Out[9]: ‘PENDING’ And it will hang like this indefinitely. Going and checking …

Total answers: 4

Why can I not catch a Queue.Empty exception from a multiprocessing Queue?

Why can I not catch a Queue.Empty exception from a multiprocessing Queue? Question: I’m trying to catch a Queue.Empty exception that is raised if a multiprocessing.Queue is empty. The following does not work: import multiprocessing f = multiprocessing.Queue() try: f.get(True,0.1) except Queue.Empty: print ‘foo’ This gives me a name error: NameError: name ‘Queue’ is not …

Total answers: 2

How to write multiple try statements in one block in python?

How to write multiple try statements in one block in python? Question: I want to do: try: do() except: do2() except: do3() except: do4() If do() fails, execute do2(), if do2() fails too, exceute do3() and so on. best Regards Asked By: alwbtc || Source Answers: You should specify the type of the exception you …

Total answers: 7

How can I quickly disable a try statement in python for testing?

How can I quickly disable a try statement in python for testing? Question: Say I have the following code: try: print ‘foo’ # A lot more code… print ‘bar’ except: pass How would I for testing purposes disable the try-statement temporary? You can’t just comment the try and except lines out as the indention will …

Total answers: 4

How to use an Exception's attributes in Python?

How to use an Exception's attributes in Python? Question: Is there a way to use the attributes/properties of an Exception object in a try-except block in Python? For example in Java we have: try { // Some code } catch(Exception e) { // Here we can use some of the attributes of “e” } What …

Total answers: 3

I want to exception handle 'list index out of range.'

I want to exception handle 'list index out of range.' Question: I am using BeautifulSoup and parsing some HTMLs. I’m getting a certain data from each HTML (using for loop) and adding that data to a certain list. The problem is, some of the HTMLs have different format (and they don’t have the data that …

Total answers: 6

Why do we need the "finally" clause in Python?

Why do we need the "finally" clause in Python? Question: I am not sure why we need finally in try…except…finally statements. In my opinion, this code block try: run_code1() except TypeError: run_code2() other_code() is the same with this one using finally: try: run_code1() except TypeError: run_code2() finally: other_code() Am I missing something? Asked By: RNA …

Total answers: 18

Extract traceback info from an exception object

Extract traceback info from an exception object Question: Given an Exception object (of unknown origin) is there way to obtain its traceback? I have code like this: def stuff(): try: ….. return useful except Exception as e: return e result = stuff() if isinstance(result, Exception): result.traceback <– How? How can I extract the traceback from …

Total answers: 6

Handle generator exceptions in its consumer

Handle generator exceptions in its consumer Question: This is a follow-up to Handle an exception thrown in a generator and discusses a more general problem. I have a function that reads data in different formats. All formats are line- or record-oriented and for each format there’s a dedicated parsing function, implemented as a generator. So …

Total answers: 8

javascript pass

javascript pass Question: Is there something along the lines of python ‘pass’ in javascript? I want to do the javascript equivalent of: try: # Something that throws exception catch: pass Asked By: Intra || Source Answers: pass is a no-op in Python. You need it for empty blocks because try: # Something that throws exception …

Total answers: 3