blob: d53da3670e3ab216b01d895eb0b518aaac273c11 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#!/usr/bin/python3.5
import asyncio
import os
async def test():
print('sleeping...')
await asyncio.sleep(3)
print('slept')
async def manage_client(reader, writer):
print('manage_client created')
print('called on connection only ?')
await asyncio.sleep(1)
print('after sleep1 in server()')
while True:
line = await reader.readline()
if not line:
break
print('line', line)
writer.write(line)
def main():
print('getting event loop')
loop = asyncio.get_event_loop()
print('got event loop')
# loop.call_soon(test)
try:
os.unlink('server_sock')
print('creating coro...')
coro = asyncio.start_unix_server(manage_client, path='server_sock')
print('coro created')
loop.run_until_complete(coro)
print('coro returned')
# loop.run_until_complete(test())
loop.run_forever()
except KeyboardInterrupt:
pass
print('loop closed')
loop.close()
if __name__ == '__main__':
main()
|