I have a loss function that opens an external .exe file for calculation, and running this executable file usually takes around 2 or 3 minutes. It works very well, but When I want to pass this function to the Genetic Algorithm for optimization, I face this error: So it obviously says that GA waited 10 sec and …
Tag: timeout
Skip the input function with timeout
I’m making any program in Python 3.7. I want to skip input function after a specific time. My code has the structure like the following rough code. I wanna skip the line TXT = input(“Enter: “) after TIMEOUT time, 0.5 sec. How can I make the code of this flow the way I want? Answer You can us…
Timeout for python requests.get entire response
I’m gathering statistics on a list of websites and I’m using requests for it for simplicity. Here is my code: Now, I want requests.get to timeout after 10 seconds so the loop doesn’t get stuck. This question has been of interest before too but none of the answers are clean. I hear that maybe…
Python socket receive – incoming packets always have a different size
I’m using the SocketServer module for a TCP server. I’m experiencing some issue here with the recv() function, because the incoming packets always have a different size, so if I specify recv(1024) (I tried with a bigger value, and smaller), it gets stuck after 2 or 3 requests because the packet le…
Using module ‘subprocess’ with timeout
Here’s the Python code to run an arbitrary command returning its stdout data, or raise an exception on non-zero exit codes: communicate is used to wait for the process to exit: The subprocess module does not support timeout–ability to kill a process running for more than X number of seconds–…
Timeout on a function call
I’m calling a function in Python which I know may stall and force me to restart the script. How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else? Answer You may use the signal package if you are running on