Skip to content

Commit

Permalink
Experimental async support
Browse files Browse the repository at this point in the history
for now only with Curio, but trio and pure asyncio planned
  • Loading branch information
tshirtman committed Jun 26, 2021
1 parent 8f43024 commit fd6be7f
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 179 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
name: base
strategy:
matrix:
python: [ '2.7', '3.5', '3.6', '3.6', '3.7']
python: [ '2.7', '3.6', '3.6', '3.7', '3.8', '3.9']
# os: ['ubuntu-latest', 'windows-latest', 'macOs-latest']
os: ['ubuntu-latest', 'windows-latest']

Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,29 @@ with OSCAsyncServer(port=8000) as OSC:
print("unknown address {}".format(address))
```

Server (curio)

```python
async def osc_app(address, port):
osc = OSCCurioServer(encoding='utf8')
osc.listen(address=address, port=port, default=True)

@osc.address("/example")
async def example(*values):
print(f"got {values} on /example")
await curio.sleep(4)
print("done sleeping")

@osc.address("/stop")
async def stop(*values):
print(f"time to leave!")
await osc.stop()

await osc.process()

curio.run(osc_app, '0.0.0.0', 8000)
```

Client

```python
Expand Down
31 changes: 31 additions & 0 deletions examples/curio_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from curio import socket

import curio

from oscpy.server import OSCCurioServer


async def osc_app(address, port):
osc = OSCCurioServer(encoding='utf8')
osc.listen(address=address, port=port, default=True)

@osc.address("/example")
async def example(*values):
print(f"got {values} on /example")
await curio.sleep(4)
print("done sleeping")

@osc.address("/test")
async def test(*values):
print(f"got {values} on /test")
await curio.sleep(4)
print("done sleeping")

@osc.address("/stop")
async def stop(*values):
print(f"time to leave!")
await osc.stop()

await osc.process()

curio.run(osc_app, '0.0.0.0', 8000)
12 changes: 12 additions & 0 deletions examples/thread_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from oscpy.server import OSCThreadServer
from time import sleep

osc = OSCThreadServer()
sock = osc.listen(address='0.0.0.0', port=8000, default=True)

@osc.address(b'/address')
def callback(*values):
print("got values: {}".format(values))

sleep(1000)
osc.stop()
Loading

0 comments on commit fd6be7f

Please sign in to comment.