xasyncio 0.1__py3-none-any.whl → 0.1.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of xasyncio might be problematic. Click here for more details.
- xasyncio/__init__.py +32 -4
- {xasyncio-0.1.dist-info → xasyncio-0.1.7.dist-info}/METADATA +2 -2
- xasyncio-0.1.7.dist-info/RECORD +5 -0
- xasyncio-0.1.dist-info/RECORD +0 -5
- {xasyncio-0.1.dist-info → xasyncio-0.1.7.dist-info}/WHEEL +0 -0
- {xasyncio-0.1.dist-info → xasyncio-0.1.7.dist-info}/licenses/LICENSE +0 -0
xasyncio/__init__.py
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import threading
|
|
3
|
+
import traceback
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ThreadingError(Exception):
|
|
7
|
+
pass
|
|
3
8
|
|
|
4
9
|
|
|
5
10
|
class ThreadedEventLoop:
|
|
@@ -8,7 +13,7 @@ class ThreadedEventLoop:
|
|
|
8
13
|
self.thread = threading.Thread(target=self.run)
|
|
9
14
|
self.events = {}
|
|
10
15
|
self.events_out_thread = {}
|
|
11
|
-
self.loop = None
|
|
16
|
+
self.loop: asyncio.BaseEventLoop = None
|
|
12
17
|
self.stopped = True
|
|
13
18
|
self.thread.start()
|
|
14
19
|
self.create_out_thread_event('loop_started')
|
|
@@ -28,6 +33,7 @@ class ThreadedEventLoop:
|
|
|
28
33
|
# print('calling from the loop thread')
|
|
29
34
|
# else:
|
|
30
35
|
# print('calling from another loop')
|
|
36
|
+
print(f'Threaded loop {self.name} stopping')
|
|
31
37
|
self.call_sync(self._stop)
|
|
32
38
|
self.thread.join(10)
|
|
33
39
|
|
|
@@ -61,7 +67,7 @@ class ThreadedEventLoop:
|
|
|
61
67
|
self.events_out_thread[name].wait()
|
|
62
68
|
|
|
63
69
|
def notify_out_thread_event(self, name):
|
|
64
|
-
print('notify event', name)
|
|
70
|
+
# print('notify event', name)
|
|
65
71
|
self.events_out_thread[name].set()
|
|
66
72
|
|
|
67
73
|
def create_event(self, name):
|
|
@@ -79,13 +85,35 @@ class ThreadedEventLoop:
|
|
|
79
85
|
def call_async(self, func, *args):
|
|
80
86
|
self.loop.call_soon_threadsafe(func, *args)
|
|
81
87
|
|
|
88
|
+
# def _sync_coro(self, coro):
|
|
89
|
+
# if threading.current_thread() != self.thread:
|
|
90
|
+
# raise ThreadingError('Invalid thread: this function must be called in the loop thread')
|
|
91
|
+
|
|
92
|
+
def await_coroutine(self, coro):
|
|
93
|
+
# task = self.loop.create_task(coro)
|
|
94
|
+
finish_event = threading.Event()
|
|
95
|
+
|
|
96
|
+
async def _helper():
|
|
97
|
+
try:
|
|
98
|
+
await coro
|
|
99
|
+
except Exception as e:
|
|
100
|
+
traceback.print_exc()
|
|
101
|
+
|
|
102
|
+
finish_event.set()
|
|
103
|
+
|
|
104
|
+
self.loop.call_soon_threadsafe(self.loop.create_task, _helper())
|
|
105
|
+
finish_event.wait()
|
|
106
|
+
|
|
82
107
|
|
|
83
108
|
def blocking_call_w_loop(loop, func, *args):
|
|
84
109
|
finish_event = threading.Event()
|
|
85
110
|
|
|
86
111
|
def _helper():
|
|
87
|
-
|
|
88
|
-
|
|
112
|
+
try:
|
|
113
|
+
func(*args)
|
|
114
|
+
finish_event.set()
|
|
115
|
+
except Exception:
|
|
116
|
+
traceback.print_exc()
|
|
89
117
|
|
|
90
118
|
loop.call_soon_threadsafe(_helper)
|
|
91
119
|
finish_event.wait()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xasyncio
|
|
3
|
-
Version: 0.1
|
|
4
|
-
Summary: A package to
|
|
3
|
+
Version: 0.1.7
|
|
4
|
+
Summary: A package to simiplify multithreaded asyncio event loops
|
|
5
5
|
Project-URL: Homepage, https://github.com/shawn-peng/xasyncio
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/shawn-peng/xasyncio/issues
|
|
7
7
|
Author-email: Yisu Peng <yisupeng@gmail.com>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
xasyncio/__init__.py,sha256=bk-3Vwq6yH3NNCkFgGKMqUCN3TnAJsGaFGgtaVWI2Z0,3996
|
|
2
|
+
xasyncio-0.1.7.dist-info/METADATA,sha256=7DSRHvyONkOwWo2kLiSrCnyiY0S7f1tRAevxnC4oTos,488
|
|
3
|
+
xasyncio-0.1.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
4
|
+
xasyncio-0.1.7.dist-info/licenses/LICENSE,sha256=fHWKRzBMuHQa8EYpadXv8pSmA8XnR8FlirkvLoayV1I,1066
|
|
5
|
+
xasyncio-0.1.7.dist-info/RECORD,,
|
xasyncio-0.1.dist-info/RECORD
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
xasyncio/__init__.py,sha256=mewp9FqqRAvpq0R7JvUisQha3s-DXN0OXlvrlw0CRK8,3178
|
|
2
|
-
xasyncio-0.1.dist-info/METADATA,sha256=NlNuwSMNgnhritpq3F3HBNSZVAzaMYk5JSWnjIxKF5U,471
|
|
3
|
-
xasyncio-0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
4
|
-
xasyncio-0.1.dist-info/licenses/LICENSE,sha256=fHWKRzBMuHQa8EYpadXv8pSmA8XnR8FlirkvLoayV1I,1066
|
|
5
|
-
xasyncio-0.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|