-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync_main.py
35 lines (28 loc) · 857 Bytes
/
async_main.py
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
import argparse
import asyncio
from async_server import AsyncServer
from caching import Cache, CsvCacheManager
parser = argparse.ArgumentParser()
parser.add_argument(
'--load', help='name of file to load cache from')
parser.add_argument(
'--save', required=True,
help='name of file to save cache in')
def main():
loop = asyncio.get_event_loop()
args = parser.parse_args()
if args.load:
cache = CsvCacheManager.load_cache_from(args.load)
else:
cache = Cache()
server = AsyncServer(loop, cache)
try:
loop.create_task(server.run())
loop.run_forever()
#loop.run_until_complete(server.run())
except KeyboardInterrupt:
print('Server shutdown')
finally:
CsvCacheManager.save_cache_to(server.cache, args.save)
if __name__ == "__main__":
main()