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

Already on GitHub? Sign in to your account

Script ends with success exit code upon failure #15

Closed
benmccann opened this Issue Nov 3, 2012 · 5 comments

Comments

Projects
None yet
3 participants

I'm calling this backup script from another process. I want to know that the process failed if there was some error, which means I want it to exit with exit code 1 instead of exit code 0. The code is littered with this pattern:

    try:
        doSomething()
    except:
        break

Can we get rid of all the exception catching? Or can we log an error and then call sys.exit(1)?

Contributor

sudorandom commented Nov 3, 2012

This might be best with a --fail-fast flag and/or a config option that will exit with an error status code... Or that could be flipped so that is the default and introduce a --catch-errors flag/option.

I guess it is nice that it backs up what it can. But it would be cool to change it so that after the backup completes it exits with the appropriate status instead of always exiting successfully.

Contributor

CrackerJackMack commented Nov 3, 2012

Some of this is horrible programming on my part. I shouldn't be doing try/except with not checking the exception type. I've already started on some of this in a local branch. Due to it using multiprocessing, bubbling up warnings is "difficult".

Contributor

sudorandom commented Nov 3, 2012

I like the idea of printing a summary at the end. Python's multiprocess pool makes it pretty easy to get return values out of finished processes through some pickling magic.

from multiprocessing import Pool
def f(x):
    return x*x

p = Pool(5)
print p.map(f, range(10))
Contributor

CrackerJackMack commented Nov 3, 2012

I used that originally in earlier development, but for large file sets it used too much memory. Though, revisiting this it appears that Pool would work, but not Pool.map(). I'll try to again with apply_async() which returns a http://docs.python.org/2/library/multiprocessing.html#multiprocessing.pool.AsyncResult which I can check for uncaught exceptions.

@ghost ghost assigned CrackerJackMack Dec 13, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment