#๐ cannot local variable 'pro' where it is not associated with a value
29 messages ยท Page 1 of 1 (latest)
@ancient sundial
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Use finally
What happens in the event the exception is triggered?
Have you created pro after that point?
thanks
No probs
you mean else?
try:
x = 1 / 0
except:
pass
finally:
print(x) # NameError
try:
x = 1 / 0
except:
pass
else:
print(x) # never runs
Indeed, you can only terminate when the call was successful.
On the other hand, when the call was successful then it already terminated. 
Wait but call doesn't even return a process.
subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False, cwd=None, timeout=None, **other_popen_kwargs)
Run the command described by args. Wait for command to complete, then return the returncode attribute.
yeah i think you'll need Popen to actually implement the behavior you're looking for
(if it doesn't already terminate the process after timing out?)
I was thinking you donโt need to terminate in this case. It automatically happens when you run into an error.
Try and except should be enough alone
funny enough the docs don't actually mention what the timeout parameter does.
I assume it's the same behavior as the newer run interface though
so subprocess.call isn't even going to stop blocking until the child process is dead anyway
It does say what it does.
The time it waits before it terminates the process
That is from the subprocess.run description, not from the subprocess.call description.
The subprocess.call description does not say what it will do with the timeout parameter. Only that it won't pass it to the Popen constructor.
But under "Exceptions" it says "All of the functions and methods that accept a timeout parameter [...] will raise TimeoutExpired if the timeout expires before the process exits."
https://docs.python.org/3/library/subprocess.html#exceptions
And the docstring of subprocess.call says "Run command with arguments. Wait for command to complete or timeout, then return the returncode attribute."
https://github.com/python/cpython/blob/main/Lib/subprocess.py#L385
nice find
doesn't seem to explicitly mention that the process will be "terminated and waited for" in the event of a timeout, though
That's true.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.