-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dh 5584/fixing the running query forever (#427)
* Dh-5584/fixing the sql query stucking for ever issue * DH-5584/updating the timeout
- Loading branch information
1 parent
f80b749
commit 40ff844
Showing
6 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import threading | ||
|
||
|
||
def run_with_timeout(func, args=(), kwargs=None, timeout_duration=60): | ||
if kwargs is None: | ||
kwargs = {} | ||
|
||
def func_wrapper(result_container): | ||
try: | ||
result_container.append(func(*args, **kwargs)) | ||
except Exception as e: | ||
result_container.append(e) | ||
|
||
result_container = [] | ||
thread = threading.Thread(target=func_wrapper, args=(result_container,)) | ||
thread.start() | ||
thread.join(timeout=timeout_duration) | ||
if thread.is_alive(): | ||
raise TimeoutError("Function execution exceeded the timeout") | ||
if result_container: | ||
if isinstance(result_container[0], Exception): | ||
raise result_container[0] | ||
return result_container[0] | ||
raise TimeoutError("Function execution exceeded the timeout") |