-
Notifications
You must be signed in to change notification settings - Fork 89
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 20a3eb9
Showing
2 changed files
with
86 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,35 @@ | ||
import threading | ||
from gi.repository import Gdk, GLib | ||
|
||
SCP_MAIN_THREAD_NAME = "SCP_MAIN_THREAD" | ||
|
||
class Blocker(): | ||
def __init__(self): | ||
self.block = True | ||
|
||
def thread_safe_blocking_call(function): | ||
""" Make function/method thread safe and block until its call is finished | ||
""" | ||
|
||
# we need a class instance because python does not support pointers | ||
blocker = Blocker() | ||
|
||
def inner_wrapper(*args, **kwargs): | ||
function(*args, **kwargs) | ||
blocker.block = False | ||
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 | ||
) | ||
while blocker.block: | ||
pass | ||
|
||
return wrapper |