Python Queue Initialization Delay

have python code that uses "multiprocessor" queues to process some information in constant separate processes. I measure the time it takes to process the information in each Process.

It is strange that the first processed item takes about 10 times longer than any other item that follows it, for about 5 seconds compared to the next paragraphs for about 0.5 seconds.

I looked at where the delay came from, and it seems like he is using the queue for the first time.

Does anyone know if there is certain overhead when setting up a queue? Is this first delay documented or am I doing something wrong?

def f(q): while 1: data = q.get(block=True) # need to wait for an input log(time.time()) # <-- first time 5 sec delay, after that min delay .... def get(data): log(time.time() q.put(data, False) q = Queue() p = Process(target=f, args=(q, )) p.daemon = True p.start() get(data) 
+4
source share

Source: https://habr.com/ru/post/1385323/


All Articles