timeout

Timeout on subprocess readline in Python

Timeout on subprocess readline in Python Question: I have a small issue that I’m not quite sure how to solve. Here is a minimal example: What I have scan_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while(some_criterium): line = scan_process.stdout.readline() some_criterium = do_something(line) What I would like scan_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while(some_criterium): line = scan_process.stdout.readline() if nothing_happens_after_10s: …

Total answers: 6

right way to run some code with timeout in Python

right way to run some code with timeout in Python Question: I looked online and found some SO discussing and ActiveState recipes for running some code with a timeout. It looks there are some common approaches: Use thread that run the code, and join it with timeout. If timeout elapsed – kill the thread. This …

Total answers: 9

SSH module for python

SSH module for python Question: I have to do a job (using my web server) on a remote machine that takes about 10 minutes. I have used pxssh module in python for the same but it gives me “timeout error”(non blocking). Now, I am using paramiko but that comes back as soon as it gives …

Total answers: 1

How to use concurrent.futures with timeouts?

How to use concurrent.futures with timeouts? Question: I am trying to get timeouts to work in python3.2 using the concurrent.futures module. However when it does timeout, it doesn’t really stop the execution. I tried with both threads and process pool executors neither of them stop the task, and only until its finished does a timeout …

Total answers: 3

Kill or terminate subprocess when timeout?

Kill or terminate subprocess when timeout? Question: I would like to repeatedly execute a subprocess as fast as possible. However, sometimes the process will take too long, so I want to kill it. I use signal.signal(…) like below: ppid=pipeexe.pid signal.signal(signal.SIGALRM, stop_handler) signal.alarm(1) ….. def stop_handler(signal, frame): print ‘Stop test’+testdir+’for time out’ if(pipeexe.poll()==None and hasattr(signal, “SIGKILL”)): …

Total answers: 6

Sql Alchemy connection time Out

Sql Alchemy connection time Out Question: I am using sqlalchemy with MySQL, and executing query with sql expression. When executing a number of query then it time out. I found an answer but it is not clear to me. Please, any one can help me? TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection …

Total answers: 2

Handling urllib2's timeout? – Python

Handling urllib2's timeout? – Python Question: I’m using the timeout parameter within the urllib2’s urlopen. urllib2.urlopen(‘http://www.example.org’, timeout=1) How do I tell Python that if the timeout expires a custom error should be raised? Any ideas? Asked By: RadiantHex || Source Answers: There are very few cases where you want to use except:. Doing this captures …

Total answers: 2

How to add a timeout to a function in Python

How to add a timeout to a function in Python Question: Many attempts have been made in the past to add timeout functionality in Python such that when a specified time limit expired, waiting code could move on. Unfortunately, previous recipes either allowed the running function to continue running and consuming resources or else killed …

Total answers: 5

Python socket receive – incoming packets always have a different size

Python socket receive – incoming packets always have a different size Question: 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 …

Total answers: 7

Keyboard input with timeout?

Keyboard input with timeout? Question: How would you prompt the user for some input but timing out after N seconds? Google is pointing to a mail thread about it at http://mail.python.org/pipermail/python-list/2006-January/533215.html but it seems not to work. The statement in which the timeout happens, no matter whether it is a sys.input.readline or timer.sleep(), I always …

Total answers: 28