-
Notifications
You must be signed in to change notification settings - Fork 0
/
PiCaApp.py
41 lines (31 loc) · 921 Bytes
/
PiCaApp.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
from Camera import Camera
from flask import Flask
import atexit
import logging
from gui.Window import Window
from State import State
import threading
logging.basicConfig(filename='app.log', filemode='w', format='%(asctime)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S')
logging.warning('App started')
app = Flask(__name__)
camera = Camera()
window = Window(camera)
# define routes
import api.routes
def exit_handler():
camera.exit()
logging.warning('App closed')
atexit.register(exit_handler)
def webserver(sharedState):
app.config['SHARED'] = sharedState
app.run(debug=True, host='localhost', use_reloader=False)
# run flask webserver in separate thread
def main():
sharedState = State(camera)
uiThread = threading.Thread(target=webserver, args=(sharedState,))
uiThread.daemon = True
uiThread.start()
window.render()
uiThread.join()
if __name__ == '__main__':
main()