Skip to content

Commit 1a4b2b3

Browse files
7 - Empty Websocket Server
1 parent 1a85c05 commit 1a4b2b3

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

index.py

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
1-
import time
2-
import asyncio # Python 3.5 +
1+
import asyncio
2+
import websockets
33

4-
iteration_times = [1, 3, 2, 4]
5-
start = time.time()
6-
total_time = 0
7-
real_time = 0
8-
async def sleeper(iteration, seconds): # coroutine
9-
global total_time
10-
global real_time
11-
func_start = time.time()
12-
print(f"{iteration}: {seconds}s")
13-
await asyncio.sleep(seconds)
14-
func_end = time.time() - func_start
15-
total_time += func_end
16-
real_time = func_end
4+
async def webhook_handler(*args, **kwargs):
5+
print(args, kwargs)
6+
pass
177

18-
async def run():
19-
results = []
20-
for iteration, second in enumerate(iteration_times):
21-
results.append(
22-
asyncio.create_task(
23-
sleeper(iteration, second)
24-
)
25-
)
26-
await asyncio.gather(*results)
278

28-
asyncio.run(run())
29-
print(f"Took {total_time} seconds in compute time")
30-
print(f"Tooke {real_time} seconds in real time")
9+
server = websockets.serve(webhook_handler, 'localhost', 8765)
10+
11+
loop = asyncio.get_event_loop()
12+
loop.run_until_complete(server)
13+
loop.run_forever()
14+
15+
# asyncio.run()

0 commit comments

Comments
 (0)