xasyncio 0.1__tar.gz → 0.1.7__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.

@@ -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.1
4
- Summary: A package to publish and receive messages
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>
@@ -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 publish and receive messages"
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,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
- func(*args)
88
- finish_event.set()
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,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