Skip to content

Commit 4203357

Browse files
committed
Experimental async support
Extract code to be reused into an OSCBaseServer class move OSCThreadServer to its own module, inheriting from OSCBaseServer Create an OSCCurioServer and an OSCThreadServer to support async usage.
1 parent 8f43024 commit 4203357

File tree

10 files changed

+454
-180
lines changed

10 files changed

+454
-180
lines changed

.github/workflows/push.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
name: base
66
strategy:
77
matrix:
8-
python: [ '2.7', '3.5', '3.6', '3.6', '3.7']
8+
python: [ '2.7', '3.6', '3.6', '3.7', '3.8', '3.9']
99
# os: ['ubuntu-latest', 'windows-latest', 'macOs-latest']
1010
os: ['ubuntu-latest', 'windows-latest']
1111

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
*.c
44
*.pyd
55
*.egg-info
6+
*.swp
7+
*.swn
8+
.coverage
9+
htmlcov/
610
.pytest_cache
711
build
812
dist

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,29 @@ with OSCAsyncServer(port=8000) as OSC:
136136
print("unknown address {}".format(address))
137137
```
138138

139+
Server (curio)
140+
141+
```python
142+
async def osc_app(address, port):
143+
osc = OSCCurioServer(encoding='utf8')
144+
osc.listen(address=address, port=port, default=True)
145+
146+
@osc.address("/example")
147+
async def example(*values):
148+
print(f"got {values} on /example")
149+
await curio.sleep(4)
150+
print("done sleeping")
151+
152+
@osc.address("/stop")
153+
async def stop(*values):
154+
print(f"time to leave!")
155+
await osc.stop()
156+
157+
await osc.process()
158+
159+
curio.run(osc_app, '0.0.0.0', 8000)
160+
```
161+
139162
Client
140163

141164
```python

examples/curio_example.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import curio
2+
3+
from oscpy.server.curio_server import OSCCurioServer
4+
5+
6+
async def osc_app(address, port):
7+
osc = OSCCurioServer(encoding='utf8')
8+
osc.listen(address=address, port=port, default=True)
9+
10+
@osc.address("/example")
11+
async def example(*values):
12+
print(f"got {values} on /example")
13+
await curio.sleep(4)
14+
print("done sleeping")
15+
16+
@osc.address("/test")
17+
async def test(*values):
18+
print(f"got {values} on /test")
19+
await curio.sleep(4)
20+
print("done sleeping")
21+
22+
@osc.address("/stop")
23+
async def stop(*values):
24+
print(f"time to leave!")
25+
await osc.stop_all()
26+
27+
await osc.process()
28+
29+
curio.run(osc_app, '0.0.0.0', 8000)

examples/thread_example.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from time import sleep
2+
3+
from oscpy.server import OSCThreadServer
4+
5+
osc = OSCThreadServer(encoding='utf8')
6+
sock = osc.listen(address='0.0.0.0', port=8000, default=True)
7+
8+
@osc.address('/address')
9+
def callback(*values):
10+
print("got values: {}".format(values))
11+
12+
13+
# exit after 1000 seconds
14+
sleep(1000)
15+
osc.stop()

examples/trio_example.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import trio
2+
3+
from oscpy.server.trio_server import OSCTrioServer
4+
5+
6+
async def osc_app(address, port):
7+
osc = OSCTrioServer(encoding='utf8')
8+
await osc.listen(address=address, port=port, default=True)
9+
10+
@osc.address("/example")
11+
async def example(*values):
12+
print(f"got {values} on /example")
13+
await trio.sleep(4)
14+
print("done sleeping")
15+
16+
@osc.address("/test")
17+
async def test(*values):
18+
print(f"got {values} on /test")
19+
await trio.sleep(4)
20+
print("done sleeping")
21+
22+
@osc.address("/stop")
23+
async def stop(*values):
24+
print(f"time to leave!")
25+
await osc.stop_all()
26+
27+
await osc.process()
28+
29+
trio.run(osc_app, '0.0.0.0', 8000)

0 commit comments

Comments
 (0)