Reputation: 79
I'm testing some code to timeout a function call using multiprocessing with Process
and Queue
. The Queue.get()
method takes an optional timeout parameter. I wrote the following test to confirm it throws a timeout error when the called process takes longer than what is allotted in the call to get
but it doesn't throw the error. Can anybody tell me how I'm failing to properly test the get
timeout? I'm on Windows 7 with python 2.
import time
from multiprocessing import Process, Queue
def f(q, t):
time.sleep(t)
q.put(0)
if __name__ == '__main__':
q = Queue()
p = Process(target=f, args=(q, 15, ))
p.start()
x = q.get(1)
print "received ", x
Upvotes: 1
Views: 1071
Reputation: 2120
From the documentation, Queue.get
receives 2 parameters: block
and timeout
, in that order. You should call it like this
q.get(timeout=1)
Upvotes: 1