File: 0001-Support-Python-3.14.patch

package info (click to toggle)
pyserial-asyncio-fast 0.16-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 236 kB
  • sloc: python: 458; makefile: 71
file content (86 lines) | stat: -rw-r--r-- 3,274 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
From: Edward Betts <edward@4angle.com>
Date: Wed, 24 Dec 2025 09:28:20 +0000
Subject: Support Python 3.14

---
 serial_asyncio_fast/__init__.py | 13 +++++++------
 test/test_asyncio.py            | 22 ++++++++++++----------
 2 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/serial_asyncio_fast/__init__.py b/serial_asyncio_fast/__init__.py
index f4c766f..75910dd 100644
--- a/serial_asyncio_fast/__init__.py
+++ b/serial_asyncio_fast/__init__.py
@@ -595,7 +595,7 @@ async def open_serial_connection(
     This function is a coroutine.
     """
     if loop is None:
-        loop = asyncio.get_event_loop()
+        loop = asyncio.get_running_loop()
     if limit is None:
         limit = asyncio.streams._DEFAULT_LIMIT
     reader = asyncio.StreamReader(limit=limit, loop=loop)
@@ -639,8 +639,9 @@ if __name__ == "__main__":
             print(self._transport.get_write_buffer_size())
             print("resume writing")
 
-    loop = asyncio.get_event_loop()
-    coro = create_serial_connection(loop, Output, "/dev/ttyUSB0", baudrate=115200)
-    transport, protocol = loop.run_until_complete(coro)
-    loop.run_forever()
-    loop.close()
+    async def main():
+        loop = asyncio.get_running_loop()
+        await create_serial_connection(loop, Output, "/dev/ttyUSB0", baudrate=115200)
+        await asyncio.Event().wait()  # Run forever
+
+    asyncio.run(main())
diff --git a/test/test_asyncio.py b/test/test_asyncio.py
index f14bc0b..e931b89 100644
--- a/test/test_asyncio.py
+++ b/test/test_asyncio.py
@@ -25,20 +25,21 @@ import serial_asyncio_fast
 HOST = "127.0.0.1"
 _PORT = 8888
 
-# on which port should the tests be performed:
-PORT = "socket://%s:%s" % (HOST, _PORT)
-
-
 @unittest.skipIf(os.name != "posix", "asyncio not supported on platform")
 class Test_asyncio(unittest.TestCase):
     """Test asyncio related functionality"""
 
     def setUp(self):
-        self.loop = asyncio.get_event_loop()
-        # create a closed serial port
+        self.loop = asyncio.new_event_loop()
+        asyncio.set_event_loop(self.loop)
+        self.server = None
 
     def tearDown(self):
+        if self.server is not None:
+            self.server.close()
+            self.loop.run_until_complete(self.server.wait_closed())
         self.loop.close()
+        asyncio.set_event_loop(None)
 
     def test_asyncio(self):
         TEXT = b"Hello, World!"
@@ -88,11 +89,12 @@ class Test_asyncio(unittest.TestCase):
                 actions.append("resume")
                 print(self._transport.get_write_buffer_size())
 
-        if PORT.startswith("socket://"):
-            coro = self.loop.create_server(Input, HOST, _PORT)
-            self.loop.run_until_complete(coro)
+        coro = self.loop.create_server(Input, HOST, _PORT)
+        self.server = self.loop.run_until_complete(coro)
+        port = self.server.sockets[0].getsockname()[1]
+        client_port = "socket://%s:%s" % (HOST, port)
 
-        client = serial_asyncio_fast.create_serial_connection(self.loop, Output, PORT)
+        client = serial_asyncio_fast.create_serial_connection(self.loop, Output, client_port)
         self.loop.run_until_complete(client)
         self.loop.run_until_complete(done.wait())
         pending = asyncio.all_tasks(self.loop)