Skip to content

Commit f86999f

Browse files
updated asgi examples to the latest uvicorn
1 parent da26cab commit f86999f

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

examples/server/asgi/app.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import asyncio
33

44
import uvicorn
5-
from uvicorn.loops.auto import auto_loop_setup
65

76
import socketio
87

98
sio = socketio.AsyncServer(async_mode='asgi')
109
app = socketio.ASGIApp(sio, static_files={
1110
'/': {'content_type': 'text/html', 'filename': 'app.html'},
1211
})
12+
background_task_started = False
1313

1414

1515
async def background_task():
@@ -68,6 +68,10 @@ async def disconnect_request(sid):
6868

6969
@sio.on('connect', namespace='/test')
7070
async def test_connect(sid, environ):
71+
global background_task_started
72+
if not background_task_started:
73+
sio.start_background_task(background_task)
74+
background_task_started = True
7175
await sio.emit('my response', {'data': 'Connected', 'count': 0}, room=sid,
7276
namespace='/test')
7377

@@ -78,6 +82,4 @@ def test_disconnect(sid):
7882

7983

8084
if __name__ == '__main__':
81-
loop = auto_loop_setup()
82-
sio.start_background_task(background_task)
83-
uvicorn.run(app, '127.0.0.1', 5000, loop=loop)
85+
uvicorn.run(app, host='127.0.0.1', port=5000)

examples/server/asgi/latency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ async def ping(sid):
1717

1818

1919
if __name__ == '__main__':
20-
uvicorn.run(app, '127.0.0.1', 5000)
20+
uvicorn.run(app, host='127.0.0.1', port=5000)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Click==7.0
22
h11==0.8.1
3-
httptools==0.0.11
4-
python-engineio==3.0.0
5-
-e [email protected]:miguelgrinberg/python-socketio@b214380d056dbbfb08273ac482633254176cb847#egg=python_socketio
3+
httptools==0.0.13
4+
python-engineio
5+
python_socketio
66
six==1.11.0
7-
uvicorn==0.3.21
8-
uvloop==0.11.3
7+
uvicorn==0.7.0
8+
uvloop==0.12.2
99
websockets==7.0

0 commit comments

Comments
 (0)