0

I try to call a method as thread then call another method while the StartServer method is background runing but when self.Thread.run() is executed, the code is stuck. Any ideas ? I try to put start server in another class, in a outside function but I still have that issue.

import time import webview import threading from flask import Flask class Windows: def __init__(self, EntryPoint = "index.html"): self.EntryPointContent = self.ReadPage(EntryPoint) self.Thread = threading.Thread(target = self.StartServer) self.Thread.daemon = True self.Thread.run() self.ShowWindows() def StartServer(self): app = Flask(__name__) app.debug = False app.reloader = False @app.route("/") def root(): return self.EntryPointContent app.run() def ReadPage(self, FileName): File = open(FileName, "r") return File.read() def ShowWindows(self): webview.create_window("Hey !", "http://localhost:5000") webview.start() app = Windows(EntryPoint="page.html") 
1
  • Try calling the class from a new thread. Commented Jul 31, 2020 at 21:52

2 Answers 2

1

Instead of Thread.run(), call Thread.start(). Run will just call your StartServer method on the current thread. Below is a short example so you can try this out.

import threading from time import sleep def l(msg): while True: print(msg) sleep(1) thread = threading.Thread(target=lambda: l('foo')) thread.start() # swap with thread.run() l('bar') 
Sign up to request clarification or add additional context in comments.

Comments

1

I'm guessing that

app.reloader = False 

isn't doing what you hope it to. Instead, try

app.run(use_reloader=False) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.