I have a simple game about hanoi towers that currently works in terminal. It allows the player to input his turn in terminal and outputs a visualization to terminal.
My task is to make a flask app that will open an html page where a JS script would poll the server for info about the game and double the visualization from terminal to the web page.
My problem is that both the game and flask have a main loop and if I run them sequently they won't work parallel.
So I need the game to run in terminal and the player to make turns in terminal, but I need the web server to get the game state and display it.
My question: what should I use for this? Threads of multiprocessing?
Say I have a flask view
from game import game
@app.route('/get_updates')
def get_updates():
return flask.jsonify(game.instance().board)
How is it gonna work if flask and the game are running in separate threads? How can I get the game object from another thread?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…