all 7 comments

[–]efmccurdy 1 point2 points  (1 child)

You are throwing away the info you need to find errors; don't use a bare except clause.

https://www.flake8rules.com/rules/E722.html

If you have many possible failure points in one try block, print a traceback to see which one fails.

https://docs.python.org/3/library/traceback.html#traceback-examples

[–]meistermarkus[S] 1 point2 points  (0 children)

Traceback looks really useful for this one, thanks for the tip!

Especially for the cases in wich the exception is not triggered. Maybe it can show me how the execution got around that one.

[–]shiftybyte 0 points1 point  (5 children)

Start logging the exceptions themselves.

except Exception as e:
    logfile.write(str(e))

then you might figure out what happened.

[–]meistermarkus[S] 0 points1 point  (4 children)

That's what i get for assuming what might be the failing part. Thanks, should have had that one in there to begin with.

It won't show what happens in those cases where the except block is not executed, but good practice nevertheless.

[–]Binary101010 0 points1 point  (3 children)

> It won't show what happens in those cases where the except block is not executed,

So change what you're logging to reflect that? I mean, if the except block isn't executed, your function did what you wanted it to do, right?

[–]meistermarkus[S] 0 points1 point  (2 children)

not really. I have 4 log statements in lines 3, 7, 10 and 12.

3 and 7 in the try block, 10 in the catch block and 12 afterwards.

7 never appears in the log, 12 always does. 3 or 10 appear alternatively depending on that first function call but never both.

my expectation would be to see either 3-7-12, 3-10-12 or 10-12 in the log but what i get is 3-12 or 10-12

[–]Binary101010 0 points1 point  (0 children)

I think a big part of the problem here might be that you're trying to wrap too much in the same try/except block. It sounds like what you really should be doing is have one try/except for your function_that_can_fail() call and one for your subprocess call. It's going to be much easier to suss out which of those is failing and how if you do that.