import sys
import threading
from PyQt4.QtGui import QMainWindow, QApplication
from astropy.utils.compat.futures import ThreadPoolExecutor
from flask import Flask, request
from flask.json import jsonify
import mainwindow
import json
import time
app = Flask(__name__)
executor = ThreadPoolExecutor(10)
@app.route('/get_01', methods=['GET', 'POST'])
def get_01():
if request.method == 'POST':
print('result::' + request.data)
data = json.loads(request.data)
body_content = data['Body']
head_value = data['Head']
code = body_content.get('Code')
reason = body_content.get('Reason')
print("Code: {}, Reason: {}, Head: {}".format(code, reason, head_value))
response_data = {
"Status": "Received",
"Body": {"Code": code, "Reason": reason},
"Head": head_value
}
time.sleep(6)
return jsonify(response_data), 200
else:
return 'GET'
@app.route('/get_02', methods=['GET', 'POST'])
def get_02():
if request.method == 'POST':
print('result::' + request.data)
data = json.loads(request.data)
body_content = data['Body']
head_value = data['Head']
code = body_content.get('Code')
reason = body_content.get('Reason')
print("Code: {}, Reason: {}, Head: {}".format(code, reason, head_value))
response_data = {
"Status": "Received",
"Body": {"Code": code, "Reason": reason},
"Head": head_value
}
time.sleep(6)
return jsonify(response_data), 200
else:
return 'GET'
@app.route('/get_03', methods=['GET', 'POST'])
def get_03():
if request.method == 'POST':
print('result::' + request.data)
data = json.loads(request.data)
body_content = data['Body']
head_value = data['Head']
code = body_content.get('Code')
reason = body_content.get('Reason')
print("Code: {}, Reason: {}, Head: {}".format(code, reason, head_value))
response_data = {
"Status": "Received",
"Body": {"Code": code, "Reason": reason},
"Head": head_value
}
return jsonify(response_data), 200
else:
return 'GET'
@app.route('/')
def home():
return "Hello, Flask is running!"
def long_task():
print('long task start')
time.sleep(6)
print("Task is done!")
def run_flask_server():
try:
app.run(debug=False, host='192.168.1.97', port=5000,threaded=True)
except Exception as e:
print('error::' + str(e))
class MyWindow(QMainWindow):
def __init__(self):
super(MyWindow, self).__init__()
self.ui = mainwindow.Ui_MainWindow()
self.ui.setupUi(self)
if __name__ == '__main__':
thread_process = threading.Thread(name='thread_process', target=run_flask_server)
thread_process.start()
app_qt = QApplication(sys.argv)
myWindow = MyWindow()
myWindow.show()
sys.exit(app_qt.exec_())