Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions being suppressed #393

Open
sciku1 opened this issue Nov 19, 2019 · 2 comments
Open

Exceptions being suppressed #393

sciku1 opened this issue Nov 19, 2019 · 2 comments

Comments

@sciku1
Copy link

sciku1 commented Nov 19, 2019

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?

@ahawker
Copy link
Owner

ahawker commented Nov 20, 2019

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!')

@sciku1
Copy link
Author

sciku1 commented Nov 20, 2019

Ahh of course, makes sense. Thanks for the suggestion, I'll give it a shot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants