My GUI lets the user play a crossword online using Flask. When it is used as a package and initialised through an executable (like the one defined in a setup.py in the entry points), it works fine. However, if I import it as a module and execute it from a python file like so —
import xpuz
xpuz.main() # initialises the gui and stuff
— I get this issue, which I will explain through a series of steps:
-
A crossword is created (attempts to initialise the flask web app)
-
This opens a duplicate gui somehow??
-
Once I “exit” the GUI (it doesn’t really close), the web app actually starts
NOTE: Pressing “destroy” results in the duplicate GUI being destroyed.
Here is my implementation of the flask app (simplified):
from multiprocessing import Process
def run_app(**kwargs):
global server
# _app_process essentially just calls Flask.run
server = Process(target=app_process, kwargs=kwargs)
server.start()
def terminate():
server.terminate()
server.join()
I know the cause of this issue is somewhere in this code I have provided, and it probably has something to do with tkinter not being threadsafe or whatever, but I don’t have much of a clue how to fix it. I have tried making it a daemon and using the threading module, but to no avail. The weirdest thing is that this happens ONLY when I am running the package directly through a python script.
Any ideas?!