-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
73 lines (54 loc) · 1.51 KB
/
run.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: UTF-8 -*-
ioloop = None
t = None
def start():
global ioloop, t
import controller
from threading import Thread
from tornado.ioloop import IOLoop
from src import messages
messages.starting()
ioloop = IOLoop.instance()
t = Thread(target=lambda: ioloop.start())
t.start()
messages.welcome()
def stop():
from src import messages
# @coroutine
def callback():
"""Stop application
Here you can stop other services, like a database ;).
Uncomment ``@coroutine`` if you want to yield futures
in this function.
"""
ioloop.stop()
ioloop.add_callback(callback)
t.join()
messages.stopped()
if __name__ == "__main__":
from src.utils import run_inside
start()
def q():
from sys import exit
stop()
exit()
def h():
from sys import modules
help(modules[__name__])
def make(goal):
from os import system
system('make %s' % goal)
@run_inside(ioloop.add_callback)
def clients():
from controller import MSGHandler
total = MSGHandler.client_count
current = len(MSGHandler.clients)
print('Connected clients: %d' % current)
print('Total connections opened: %d' % total)
print(
'Total connections closed: %d' % (total-current)
)
@run_inside(ioloop.add_callback)
def bcast(message):
from controller import MSGHandler
MSGHandler.broadcast(message)