Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
48 lines (35 loc) · 1.01 KB

File metadata and controls

48 lines (35 loc) · 1.01 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import uuid
import threading
class Task:
"""
线程需要执行的逻辑任务
"""
def __init__(self, func, *args, **kwargs):
self.callable = func
self.id = uuid.uuid4()
self.args = args
self.kwargs = kwargs
def __str__(self):
return "Task ID: " + str(self.id)
class AsyncTask(Task):
def __init__(self, func, *args, **kwargs):
self.result = None
self.condition = threading.Condition()
super().__init__(func, *args, **kwargs)
def set_result(self, result):
self.condition.acquire()
self.result = result
self.condition.notify()
self.condition.release()
def get_result(self):
self.condition.acquire()
if not self.result:
self.condition.wait()
result = self.result
self.condition.release()
return result
def my_func(*args, **kwargs):
print("this is a testing text")
if __name__ == '__main__':
task = Task(func=my_func)
print(task)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.