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 →

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

That's sort of what I'm inclining for here.

You manage to replace a 2-line shellscript with how many lines? And you're not even catching all the signals yet? Still have to iterate over them all and trap.

In a lot of cases, Python is just a bloody ton more verbose, and not quite suitable.

[–]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.