Flask-Restx(/Flask-Restplus) detect reload - python-3.x

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.
Now when I do changes as usual the Debugger still shows * Detected change in 'XXXXX', reloading which is a useful feature. 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. 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. Or is there at least a possibility to not block the reload in order to proceed reloading the flask-restx-related stuff?
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. 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()

Related

Programing Rust to stop safety with systemctl

I'm writing a very demanding program in rust that had variable Threads for processing very important data, and want to know if there is a way that i can send a signal to stop it with systemctl in a way that i can be sure that it is finishing it's dutties before stop, as its very demanding, uses http_request, and threads are variables I can not make an estimation of how much time i have to wait since signal sended until the process is dead.
In esscense, it is a daemon that is in a loop until a variable sets false, like this
loop {
// Process goes here
if !is_alive {
break;
}
}
What i'm doing right now is that the program is asking a "config.json" file if it is "alive", but i think it's not the best way because i don't know when the program stops, just can see that is stoping, but not how much is going to last, and if i do this way, systemctl is going to show the service alive, even if i shuted it down manually.
If you want to experiment with Systemd service behavior, I would take a look at the Systemd documentation. In this case, I would direct you to the section about TimeoutStopSec.
According to the documentation, you can disable any timeout on systemd stop commands with TimeoutStopSec=infinity. This combined with actually handling the SIGTERM signal that systemd uses by default should do the trick.
Furthermore, there is the KillSignal option by which you can specify the signal that is sent to your program to stop it or ExecStop to specify a program to run in order to stop your service.
With these you should be able to figure it out, I hope.

Thread-breakpoints in intellij idea don't work

I've written a simple IRC-proxy for a single client with a built-in bot.
It spawns two threads, one reading from the client and feeding the server and the other doing the oppisite.
So far it works correctly. But if I put a breakpoint within the run()-methods of the thread-object, the IDE will never stop there. Breakpoints in the main-thread stop correctly.
What am I doing wrong here?
You have the change the suspend policy for breakpoints to thread as documented here.
You would do this like so:
The following shows usage of the thread suspend policy. Notice how the Console does not have anything printed on it and also that ALL the threads have stopped on the breakpoint:
The following shows the same breakpoint with the default Suspend All policy and how changing it to Thread on-the-fly results in stopping any threads that hit that breakpoint after that change:

Freeing a component from Thread in Delphi

I have written a thread to check if there are any freeze in mainform. I am doing this because sometimes TWebbrowser freezes main UI. I think it is because of a javascript and i can not reproduce this problem.
What i need is to safely stop TWebbrowser's job. Actually it should be in a loop or waiting for something but it freezes somehow. Well what i need is to detect and kill the browser and recreate it.
This is how i detect the freeze:
bFreeze := SendMessageTimeout(hwn, WM_NULL, 0, 0, SMTO_ABORTIFHUNG OR SMTO_BLOCK, TIME_OUT, iRes) <= 0;
Any advice will be greatly appreciated.
Thanks
You are running the browser control from your program's main thread. Any attempt to forcibly terminate the browser thread will bring down your entire program. If you have code that can hang, and you wish to recover from that, then it is just not realistic to expect to run that code from your main thread.
Modern browsers deal with this problem by isolating each page in a distinct process. Then if that page hangs in some way, or crashes, the page process can be killed without impacting on the other pages open in the browser.
If you really want to have similar robustness you'll need to have a similar architecture. You might be tempted to think you can isolate a page in a thread within a single process but in practise this doesn't give sufficient isolation.
Perhaps a more tenable solution is to avoid the hang in the first place. Maybe you need to make sure that you are using the latest browser engine. Did you specify that in the browser feature emulation registry key?

Provide updates to Qt GUI from sub thread

I know very similar questions have been asked before, but I am unable to find an answer for my specific problem. I have a main (GUI) thread which upon button press initializes a worker thread to perform some analysis. I am using signals and slots to communicate between my worker thread and my GUI thread (i.e. when the thread starts and when it finishes), but I need to go deeper than that. My worker thread actually calls another class in a separate implementation file which then iterates through a series of calculations which are sent to std::cout for each iteration (as the code used to be a console application for which I am now writing a GUI). I am trying to feed those outputs for each iteration back into my GUI thread so that my text browser is updated in real time as my code iterates. The problem is, when I emit a signal from the class my worker thread calls, it is not picked up by the GUI thread. I do not get any errors. Does anyone have any suggestions on how to transmit a signal to the GUI from a class that my worker thread is calling? I can post code as required, but I'm not sure what would be most helpful to see and my code is quite extensive (it's an aircraft performance application). Any help would be greatly appreciated. Thank you kindly!
1) Make sure the connect() call for connecting you signal returns true. If it does not, qdebug output usually tells you what is wrong
2) You should use the QueuedConnection type (the default (Auto) should work also)

Stop uwsgi performing harakiri (seriously)

I've been trying to track down a problem with uwsgi where the uwsgi process kills itself.
The oh-so-helpful log files just say...
F*CK !!! i must kill myself (pid: 9984 app_id: 0)...
A little Googling led me to this line in the source code...
void harakiri() {
uwsgi_log("\nF*CK !!! i must kill myself (pid: %d app_id: %d)...\n", uwsgi.mypid, uwsgi.wsgi_req->app_id);
//Some other stuff
exit(0);
}
Whether it dies or not varies but seems (from Googling) to be tied to how long a request takes. In this instance, the request is streaming back a dynamically generated Pdf. The generation happens in the background but once it's complete, a new request comes in to retrieve it. The Pdf can be potentially quite large (worst-case, 50-60MB) which - depending on the connection - speed explains why requests might reach a timeout threshold.
How can I configure uwsgi to either never time out or have extremely high timeouts? The app is being used on private networks and I'd rather it was slow and succeeded than died.
harakiri is something you voluntary enable with --harakiri, by default there is no such feature. Check your configuration for it.
Another possibility could be you are running without the master process (you should have a warning about it) and set an alarm() without defining a signal handler for SIGALRM

Resources