Added file transfer from web to flask server

This commit is contained in:
Igor Nurullaev
2019-08-28 18:21:02 +03:00
parent 30ea2d6ab3
commit 6c3af9382d
7 changed files with 341 additions and 27 deletions

55
Server/flask_test.py Normal file
View File

@@ -0,0 +1,55 @@
import threading
import atexit
from flask import Flask
from server import *
POOL_TIME = 0 # Seconds
class ServerThread(threading.Thread):
def run(self):
server = Server()
server.start()
while True:
pass
# variables that are accessible from anywhere
commonDataStruct = {}
# lock to control access to variable
dataLock = threading.Lock()
# thread handler
yourThread = ServerThread()
def create_app():
app = Flask(__name__)
def interrupt():
global yourThread
yourThread.cancel()
def doStuff():
global commonDataStruct
global yourThread
with dataLock:
print('kek')
yourThread = threading.Timer(POOL_TIME, doStuff, ())
yourThread.start()
def doStuffStart():
# Do initialisation stuff here
global yourThread
# Create your thread
yourThread = threading.Timer(POOL_TIME, doStuff, ())
yourThread.start()
# Initiate
doStuffStart()
# When you kill Flask (SIGTERM), clear the trigger for the next thread
atexit.register(interrupt)
return app
app = create_app()
app.run(host='0.0.0.0', debug=True)