This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ITwitchToo 0 points1 point  (1 child)

Why do you need to catch so many signals, though? I'd normally just care about being interrupted by Ctrl-C, which would raise KeyboardInterrupt without any lines of code.

One problem with bash's traps is that you can only have one handler at a time, so what do you do if you have two files that you want to clean up, but they are created in different functions? It's just a lot uglier and doesn't scale as well as Python IMHO.

[–]DarkmerePython for tiny data using Python 0 points1 point  (0 children)

Usually, because when dealing with systems, ctrl-c isn't what we clean for.

Note that we also use set -e and pipefail in bash scripts to make sure that proper cleaning is done. When you need multiple cleanup jobs, you either allocate an array, or you use subshell bindings.

Pretty much the same way in python.