Home > Blockchain >  Sending multiple items through the same queue?
Sending multiple items through the same queue?

Time:08-25

I want to simultaneously send 2 items of data through a queue for an *args input however I can't seem to figure out if it's possible.

import numpy as np
import queue

def set_data(*data):
    first, second = data
    print(first, second)

q = queue.Queue()
array1, array2 = np.zeros((10, 3), dtype=float), np.zeros((10, 3), dtype=float)

q.put(array1, array2)
c, v = q.get()

set_data(c, v)

Does anyone know a way to make this work?

Much appreciated

CodePudding user response:

The Queue.put function signature is:

put(item, block=True, timeout=None)

Passing two parameters sets item to array1 and block to array2. You want to pass them as a single parameter to item as either a tuple or list, e.g.:

q.put((array1, array2))
  • Related