I'm invoking git
as a shell command, and want to timeout after X
amount of seconds and terminate the operation.
I've considered multiprocessing.Process
, since it has join()
with a timeout and terminate()
. However, I'd prefer using a thread for a couple of reasons:
- It's more lightweight
- The code invoking the
git
is already running in amultiprocessing.Process
withdaemon=True
, and so cannot spawn child processes itself (except if I changedaemon=False
, but then the parent of the spawning process won't its child).
How can I run the git
command in a thread using a timeout, and terminate the thread if
the timeout has elapsed?