xasyncio 0.1__tar.gz → 0.2.0__tar.gz
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-0.2.0/.github/workflows/release.yml +77 -0
- {xasyncio-0.1 → xasyncio-0.2.0}/PKG-INFO +2 -2
- {xasyncio-0.1 → xasyncio-0.2.0}/pyproject.toml +6 -3
- {xasyncio-0.1 → xasyncio-0.2.0}/src/xasyncio/__init__.py +44 -10
- xasyncio-0.1/.github/workflows/release.yml +0 -53
- {xasyncio-0.1 → xasyncio-0.2.0}/.gitignore +0 -0
- {xasyncio-0.1 → xasyncio-0.2.0}/LICENSE +0 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
|
|
2
|
+
|
|
3
|
+
on: push
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
test:
|
|
7
|
+
name: Run tests 🧪
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
with:
|
|
13
|
+
persist-credentials: false
|
|
14
|
+
- name: Set up Python
|
|
15
|
+
uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.x"
|
|
18
|
+
- name: Install pytest
|
|
19
|
+
run: >-
|
|
20
|
+
python3 -m
|
|
21
|
+
pip install
|
|
22
|
+
pytest
|
|
23
|
+
--user
|
|
24
|
+
- name: Install a dev package
|
|
25
|
+
run: pip install -e .
|
|
26
|
+
- name: Run tests
|
|
27
|
+
run: pytest
|
|
28
|
+
|
|
29
|
+
build:
|
|
30
|
+
name: Build distribution 📦
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
needs: test
|
|
33
|
+
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/checkout@v4
|
|
36
|
+
with:
|
|
37
|
+
persist-credentials: false
|
|
38
|
+
- name: Set up Python
|
|
39
|
+
uses: actions/setup-python@v5
|
|
40
|
+
with:
|
|
41
|
+
python-version: "3.x"
|
|
42
|
+
- name: Install pypa/build
|
|
43
|
+
run: >-
|
|
44
|
+
python3 -m
|
|
45
|
+
pip install
|
|
46
|
+
build
|
|
47
|
+
--user
|
|
48
|
+
- name: Build a binary wheel and a source tarball
|
|
49
|
+
run: python3 -m build
|
|
50
|
+
- name: Store the distribution packages
|
|
51
|
+
uses: actions/upload-artifact@v4
|
|
52
|
+
with:
|
|
53
|
+
name: python-package-distributions
|
|
54
|
+
path: dist/
|
|
55
|
+
|
|
56
|
+
publish-to-pypi:
|
|
57
|
+
name: >-
|
|
58
|
+
Publish Python 🐍 distribution 📦 to PyPI
|
|
59
|
+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
|
|
60
|
+
needs:
|
|
61
|
+
- build
|
|
62
|
+
runs-on: ubuntu-latest
|
|
63
|
+
environment:
|
|
64
|
+
name: pypi
|
|
65
|
+
url: https://pypi.org/p/xasyncio
|
|
66
|
+
permissions:
|
|
67
|
+
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
68
|
+
|
|
69
|
+
steps:
|
|
70
|
+
- name: Download all the dists
|
|
71
|
+
uses: actions/download-artifact@v4
|
|
72
|
+
with:
|
|
73
|
+
name: python-package-distributions
|
|
74
|
+
path: dist/
|
|
75
|
+
- name: Publish distribution 📦 to PyPI
|
|
76
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
77
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xasyncio
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: A package to
|
|
3
|
+
Version: 0.2.0
|
|
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>
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["hatchling"]
|
|
2
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
3
3
|
build-backend = "hatchling.build"
|
|
4
4
|
|
|
5
|
+
[tool.hatch.version]
|
|
6
|
+
source = "vcs"
|
|
7
|
+
|
|
5
8
|
[tool.hatch.build]
|
|
6
9
|
exclude = [
|
|
7
10
|
"/tests",
|
|
8
11
|
]
|
|
9
12
|
|
|
10
13
|
[project]
|
|
14
|
+
dynamic = ["version"]
|
|
11
15
|
name = "xasyncio"
|
|
12
|
-
version = "0.1"
|
|
13
16
|
authors = [
|
|
14
17
|
{ name="Yisu Peng", email="yisupeng@gmail.com" },
|
|
15
18
|
]
|
|
16
|
-
description = "A package to
|
|
19
|
+
description = "A package to simiplify multithreaded asyncio event loops"
|
|
17
20
|
#readme = "README.md"
|
|
18
21
|
requires-python = ">=3.7"
|
|
19
22
|
classifiers = [
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import threading
|
|
3
|
+
import traceback
|
|
3
4
|
|
|
5
|
+
from typing import *
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
|
|
8
|
+
class ThreadingError(Exception):
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AsyncThread(threading.Thread):
|
|
6
13
|
def __init__(self, name):
|
|
14
|
+
super().__init__()
|
|
7
15
|
self.name = name
|
|
8
|
-
self.thread = threading.Thread(target=self.run)
|
|
9
16
|
self.events = {}
|
|
10
17
|
self.events_out_thread = {}
|
|
11
|
-
self.loop = None
|
|
18
|
+
self.loop: asyncio.BaseEventLoop | None = None
|
|
12
19
|
self.stopped = True
|
|
13
|
-
self.
|
|
20
|
+
self.start()
|
|
14
21
|
self.create_out_thread_event('loop_started')
|
|
15
22
|
self.wait_out_thread_event('loop_started')
|
|
16
23
|
|
|
@@ -28,8 +35,10 @@ class ThreadedEventLoop:
|
|
|
28
35
|
# print('calling from the loop thread')
|
|
29
36
|
# else:
|
|
30
37
|
# print('calling from another loop')
|
|
38
|
+
print(f'Threaded loop {self.name} stopping')
|
|
31
39
|
self.call_sync(self._stop)
|
|
32
|
-
self.thread.join(10)
|
|
40
|
+
# self.thread.join(10)
|
|
41
|
+
self.join(10)
|
|
33
42
|
|
|
34
43
|
def _mark_running(self, running=True):
|
|
35
44
|
# if running:
|
|
@@ -40,11 +49,14 @@ class ThreadedEventLoop:
|
|
|
40
49
|
|
|
41
50
|
def run(self):
|
|
42
51
|
self.loop = asyncio.new_event_loop()
|
|
43
|
-
# self.loop = asyncio.get_event_loop()
|
|
44
52
|
# Need to call this in the loop, mainly because need to make sure the loop is running
|
|
53
|
+
# debugging version
|
|
45
54
|
# self.loop.call_soon_threadsafe(
|
|
46
55
|
# lambda: (
|
|
47
|
-
# print('notifying loop started'),
|
|
56
|
+
# print('notifying loop started'),
|
|
57
|
+
# self._mark_running(),
|
|
58
|
+
# print(self.stopped),
|
|
59
|
+
# self.notify_out_thread_event('loop_started')))
|
|
48
60
|
self.loop.call_soon_threadsafe(
|
|
49
61
|
lambda: (
|
|
50
62
|
self._mark_running(), self.notify_out_thread_event('loop_started')
|
|
@@ -61,7 +73,7 @@ class ThreadedEventLoop:
|
|
|
61
73
|
self.events_out_thread[name].wait()
|
|
62
74
|
|
|
63
75
|
def notify_out_thread_event(self, name):
|
|
64
|
-
print('notify event', name)
|
|
76
|
+
# print('notify event', name)
|
|
65
77
|
self.events_out_thread[name].set()
|
|
66
78
|
|
|
67
79
|
def create_event(self, name):
|
|
@@ -79,13 +91,35 @@ class ThreadedEventLoop:
|
|
|
79
91
|
def call_async(self, func, *args):
|
|
80
92
|
self.loop.call_soon_threadsafe(func, *args)
|
|
81
93
|
|
|
94
|
+
# def _sync_coro(self, coro):
|
|
95
|
+
# if threading.current_thread() != self.thread:
|
|
96
|
+
# raise ThreadingError('Invalid thread: this function must be called in the loop thread')
|
|
97
|
+
|
|
98
|
+
def await_coroutine(self, coro):
|
|
99
|
+
# task = self.loop.create_task(coro)
|
|
100
|
+
finish_event = threading.Event()
|
|
101
|
+
|
|
102
|
+
async def _helper():
|
|
103
|
+
try:
|
|
104
|
+
await coro
|
|
105
|
+
except Exception as e:
|
|
106
|
+
traceback.print_exc()
|
|
107
|
+
|
|
108
|
+
finish_event.set()
|
|
109
|
+
|
|
110
|
+
self.loop.call_soon_threadsafe(self.loop.create_task, _helper())
|
|
111
|
+
finish_event.wait()
|
|
112
|
+
|
|
82
113
|
|
|
83
114
|
def blocking_call_w_loop(loop, func, *args):
|
|
84
115
|
finish_event = threading.Event()
|
|
85
116
|
|
|
86
117
|
def _helper():
|
|
87
|
-
|
|
88
|
-
|
|
118
|
+
try:
|
|
119
|
+
func(*args)
|
|
120
|
+
finish_event.set()
|
|
121
|
+
except Exception:
|
|
122
|
+
traceback.print_exc()
|
|
89
123
|
|
|
90
124
|
loop.call_soon_threadsafe(_helper)
|
|
91
125
|
finish_event.wait()
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
|
|
2
|
-
|
|
3
|
-
on: push
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
build:
|
|
7
|
-
name: Build distribution 📦
|
|
8
|
-
runs-on: ubuntu-latest
|
|
9
|
-
|
|
10
|
-
steps:
|
|
11
|
-
- uses: actions/checkout@v4
|
|
12
|
-
with:
|
|
13
|
-
persist-credentials: false
|
|
14
|
-
- name: Set up Python
|
|
15
|
-
uses: actions/setup-python@v5
|
|
16
|
-
with:
|
|
17
|
-
python-version: "3.x"
|
|
18
|
-
- name: Install pypa/build
|
|
19
|
-
run: >-
|
|
20
|
-
python3 -m
|
|
21
|
-
pip install
|
|
22
|
-
build
|
|
23
|
-
--user
|
|
24
|
-
- name: Build a binary wheel and a source tarball
|
|
25
|
-
run: python3 -m build
|
|
26
|
-
- name: Store the distribution packages
|
|
27
|
-
uses: actions/upload-artifact@v4
|
|
28
|
-
with:
|
|
29
|
-
name: python-package-distributions
|
|
30
|
-
path: dist/
|
|
31
|
-
|
|
32
|
-
publish-to-pypi:
|
|
33
|
-
name: >-
|
|
34
|
-
Publish Python 🐍 distribution 📦 to PyPI
|
|
35
|
-
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
|
|
36
|
-
needs:
|
|
37
|
-
- build
|
|
38
|
-
runs-on: ubuntu-latest
|
|
39
|
-
environment:
|
|
40
|
-
name: pypi
|
|
41
|
-
url: https://pypi.org/p/xasyncio
|
|
42
|
-
permissions:
|
|
43
|
-
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
44
|
-
|
|
45
|
-
steps:
|
|
46
|
-
- name: Download all the dists
|
|
47
|
-
uses: actions/download-artifact@v4
|
|
48
|
-
with:
|
|
49
|
-
name: python-package-distributions
|
|
50
|
-
path: dist/
|
|
51
|
-
- name: Publish distribution 📦 to PyPI
|
|
52
|
-
uses: pypa/gh-action-pypi-publish@release/v1
|
|
53
|
-
|
|
File without changes
|
|
File without changes
|