File tree Expand file tree Collapse file tree 1 file changed +12
-27
lines changed Expand file tree Collapse file tree 1 file changed +12
-27
lines changed Original file line number Diff line number Diff line change 1
- import time
2
- import asyncio # Python 3.5 +
1
+ import asyncio
2
+ import websockets
3
3
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
17
7
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 )
27
8
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()
You can’t perform that action at this time.
0 commit comments