-
Notifications
You must be signed in to change notification settings - Fork 1
/
start.py
113 lines (97 loc) · 3.13 KB
/
start.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- coding: utf-8 -*-
#!/usr/bin/python3
"""
This file is part of egg-force-one.
egg-force-one is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Foobar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with egg-force-one. If not, see <http://www.gnu.org/licenses/>. 2
############################################################################
Created on Mon Sep 25 16:24:39 2017
@author: CASAL Guillaume
"""
#import externe
import os
import time
from requests import get
#import egg force one
import sysVar
usb = sysVar.usb
control = sysVar.control
webUser = sysVar.webUser
os.chdir(os.path.dirname(os.path.realpath(__file__))) # nous place dans le dossier de l'executable
#print(os.path.dirname(os.path.realpath(__file__)))
def startUsb (sysVar):
threadUsb = usb.Usb(sysVar)
sysVar.threadUsb = threadUsb
threadUsb.setDaemon(True)
threadUsb.setName("usb egg force one")
threadUsb.start()
pass
def startControl(sysVar):
threadControl = control.Control(sysVar)
sysVar.threadControl = threadControl
threadControl.setDaemon(True)
threadControl.setName("control egg force one")
threadControl.start()
pass
def startWebUser(sysVar):
threadWebUser = webUser.WebUser(sysVar)
sysVar.threadWebUser = threadWebUser
threadWebUser.setDaemon(True)
threadWebUser.setName("web user egg force one")
threadWebUser.start()
pass
def startAll(sysVar):
startWebUser(sysVar)
startControl(sysVar)
startUsb (sysVar)
pass
def alwaysAlive(sysVar):
hz = 1/10 #optimisation
while (sysVar.alive == 0):
time.sleep(hz)
if (sysVar.threadUsb.isAlive() == False):
if (sysVar.alive == 0):
print("bug usb:" + str(sysVar.alive))
startUsb(sysVar)
sysVar.alive = 2
pass
pass
if (sysVar.threadControl.isAlive() == False):
if (sysVar.alive == 0):
print("bug control:" + str(sysVar.alive))
startControl(sysVar)
sysVar.alive = 3
pass
pass
if (sysVar.threadWebUser.isAlive() == False):
if (sysVar.alive == 0):
print("bug web user:" + str(sysVar.alive))
startWebUser(sysVar)
sysVar.alive = 4
pass
pass
pass
try:
while (True):
get('http://' + str(sysVar.webHost) + ":"+ str(sysVar.webPort) + '/shutdown')
pass
pass
except:
pass
pass
def start():
startAll(sysVar)
alwaysAlive(sysVar)
return sysVar.alive
if __name__ == "__main__":
#cProfile.run("start()")
start()
pass