-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
46 lines (32 loc) · 1005 Bytes
/
main.py
File metadata and controls
46 lines (32 loc) · 1005 Bytes
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
import asyncio
import logging
from upnp_server.app import HttpApplication
from ssdp_server.app import SSDPApplication
logging.basicConfig(level=logging.DEBUG)
class Application:
log = logging.getLogger(__name__)
def __init__(self):
self.loop = asyncio.get_event_loop()
self.servers = []
self.log.info("Application initialized")
def add_server(self, server):
self.servers.append(
server(self.loop)
)
self.log.info("Server %s added", server)
def run(self):
try:
self.log.info("Application started")
self.loop.run_forever()
except KeyboardInterrupt: # pragma: no cover
self.log.info("Stopping server...")
finally:
self.stop()
def stop(self):
for server in self.servers:
server.stop()
if __name__ == '__main__':
app = Application()
app.add_server(SSDPApplication)
app.add_server(HttpApplication)
app.run()