crython
crython copied to clipboard
Exceptions being suppressed
Hello, let me start off by saying I'm a bit of a python beginner so excuse me if there's a well-documented way to solve this.
I noticed that if an exception occurs while a job is happening, the stack trace is not shown on the console. I wanted to pipe that output into a file or something so I can review, or better yet, pipe all exception stack traces to a function that logs to slack.
Is there a way to disable the exception output suppression?
The scheduler runs in a separate thread and each invocation of each function that needs to be run is executed in a separate thread/process context (depending on the ctx
param).
The exception is being eaten because it happens in this background thread and we don't capture it and pass it back to the calling thread.
For now, if you catch the exceptions within your functions, it should work as expected. I would imagine writing a decorator (if you have many functions) to simplify the process. Some pseudo-code:
import crython
def exception_to_slack(func):
def decorator(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
slack.notify_me_on_exception(func.__name__, e)
return decorator
@crython.job(expr='* * * * * * *')
@exception_to_slack
def say_hello():
print('Hello')
raise RuntimeError('Oops!')
Ahh of course, makes sense. Thanks for the suggestion, I'll give it a shot!