'Wrapper for function with variable execute time
I have a function that, depending on the input, can take seconds or days to execute (no set time limit). If the function execution is long running, I need to take certain actions on a regular interval (like recording the log every 5 min). I want to implement a wrapper that does this activity on regular interval but proceed as soon as the function execution completes. Check and sleep does not work for me as I do not want to waste time sleeping even though the function execution is complete.
Solution 1:[1]
The first solution coming to mind is building a decorator where the wrapper starts a thread, which then logs whatever you wish and you terminate the thread when the execution ends.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | NoBlockhit |
