forked from Tribler/tribler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
32 lines (27 loc) · 1002 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Written by Egbert Bouman
'''
The Libtorrent package contains code to manage the torrent library.
'''
def checkHandleAndSynchronize(default=None):
def wrap(f):
def invoke_func(*args, **kwargs):
download = args[0]
with download.dllock:
if download.handle and download.handle.is_valid():
return f(*args, **kwargs)
return default
return invoke_func
return wrap
def waitForHandleAndSynchronize(default=None):
def wrap(f):
def invoke_func(*args, **kwargs):
download = args[0]
with download.dllock:
if download.handle and download.handle.is_valid():
return f(*args, **kwargs)
else:
lambda_f = lambda a = args, kwa = kwargs: invoke_func(*a, **kwa)
download.session.lm.threadpool.add_task(lambda_f, 1)
return default
return invoke_func
return wrap