简体   繁体   English

Flask-Restx(/Flask-Restplus) 检测重载

[英]Flask-Restx(/Flask-Restplus) detect reload

my problem is the following: In my Flask-Restx-Application I created a Runner-Thread which runs asynchronously to the main-thread of the Flask-Application.我的问题如下:在我的 Flask-Restx-Application 中,我创建了一个 Runner-Thread,它与 Flask-Application 的主线程异步运行。

Now when I do changes as usual the Debugger still shows * Detected change in 'XXXXX', reloading which is a useful feature.现在,当我像往常一样进行更改时,调试器仍然显示* Detected change in 'XXXXX', reloading这是一个有用的功能。 The problem is that now it got stuck and cannot reload because of the running Thread which must be stopped manually.问题是现在它卡住了并且由于必须手动停止正在运行的线程而无法重新加载。

I would still like to use the automatic reload if possible in combination with the asynchronous Runner-Thread.如果可能的话,我仍然希望将自动重新加载与异步 Runner-Thread 结合使用。 Is there a possibility to "detect" those reloads by triggering an Event or something similar?是否有可能通过触发事件或类似的东西来“检测”这些重新加载? Then I could manually shutdown the Runner-Thread and restart it with the application.然后我可以手动关闭 Runner-Thread 并使用应用程序重新启动它。 Or is there at least a possibility to not block the reload in order to proceed reloading the flask-restx-related stuff?或者至少有可能不阻止重新加载以继续重新加载与flask-restx相关的东西?

Thanks in advance for any help.提前感谢您的帮助。

PS: I find it hard to add code here because I do not know which parts of the flask-app are important. PS:我发现这里很难添加代码,因为我不知道烧瓶应用程序的哪些部分很重要。 If you need any code to answer the question I will add it in an Edit.如果您需要任何代码来回答问题,我会将其添加到编辑中。

You need to make your thread a daemon thread if you want the reloader to work.如果您希望重新加载器工作,您需要使您的线程成为守护线程。 The reloader will try to kill and restart the program (by killing the main thread), but because your other thread is not a daemon, it will fail to kill the program and reload it.重新加载器将尝试终止并重新启动程序(通过终止主线程),但由于您的其他线程不是守护程序,因此它将无法终止程序并重新加载它。 A daemon thread is one that only lives as long as the main thread lives, and therefore making your other thread a daemon will fix your issue.守护线程是一个只在主线程存在的情况下存在的线程,因此使您的另一个线程成为守护线程将解决您的问题。 Here is an example:这是一个例子:

from threading import Thread

...

t = Thread(...)
t.daemon = True # this makes your thread a daemon thread
t.start()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM