-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to remove all gdk threads_enter and leave calls
- Loading branch information
1 parent
e58d4c9
commit d4e7f11
Showing
2 changed files
with
80 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import threading | ||
from gi.repository import Gdk, GLib | ||
|
||
SCP_MAIN_THREAD_NAME = "SCP_MAIN_THREAD" | ||
|
||
def thread_safe_blocking_call(function): | ||
""" Make function/method thread safe and block until its call is finished | ||
""" | ||
|
||
blocker = threading.Event() | ||
|
||
def inner_wrapper(*args, **kwargs): | ||
function(*args, **kwargs) | ||
blocker.set() | ||
return False | ||
|
||
def wrapper(*args, **kwargs): | ||
# if this is the main thread then simply return function | ||
if threading.current_thread().name == SCP_MAIN_THREAD_NAME: | ||
return function(*args, **kwargs) | ||
Gdk.threads_add_idle( | ||
GLib.PRIORITY_DEFAULT_IDLE, | ||
inner_wrapper, | ||
*args, | ||
**kwargs | ||
) | ||
blocker.wait() | ||
|
||
return wrapper |