-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
78 lines (63 loc) · 2.06 KB
/
run.py
File metadata and controls
78 lines (63 loc) · 2.06 KB
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
74
75
76
77
78
import gevent.monkey
gevent.monkey.patch_all(thread=False, time=False)
import webserver.hostfile as hostfile
import webserver.functionDivider
import webserver.functionCaller
import threading
import time
# import Team_auto.Car as car
import werkzeug.serving
import sys
from socketio.server import SocketIOServer
from werkzeug.wsgi import SharedDataMiddleware
__author__ = 'Thomas'
app = hostfile.app
def proces_forever():
while True:
print "running"
try:
FD.processTime(100)
except:
sys.exc_traceback.format_exc()
finally:
proces_forever()
def updateValues():
while True:
# print "updating is so fun: ", webserver.functionDivider.car.isUpdated
time.sleep(0.1)
if webserver.functionDivider.car.isUpdated:
hostfile.sendPower(webserver.functionDivider.car.get_power_values())
#print "is was TRUEEEEEEEEEEEEEEEEEEEEEE-----------------------------"
webserver.functionDivider.car.isUpdated = False
def main():
global FD
FD = webserver.functionDivider.getFunctionDivider()
process = threading.Thread(target=proces_forever, name='processing')
process.setDaemon(True)
process.start()
#process2 = threading.Thread(target=updateValues, name='updatingValues')
#process2.setDaemon(True)
#process2.start()
app.debug = True
server = SocketIOServer(
('0.0.0.0', 4848),
SharedDataMiddleware(app, {}),
namespace="socket.io",
policy_server=False)
server.serve_forever()
# add other proces for adjusting to obstacles etc
# hostfile.http.serve_forever()
def gunicorn():
global FD
FD = webserver.functionDivider.getFunctionDivider()
process = threading.Thread(target=proces_forever, name='processing')
process.setDaemon(True)
process.start()
# hostfile.socket.run(hostfile.app, host='0.0.0.0', port=4848)
if __name__ == "__main__":
print "run.py is main"
main()
else:
print "running thread function, server must be started with gunicorn"
gunicorn()
## main()