Hi,
in a data acquisition program I have several threads,
one thread grabbing images and another doing some
processing.
I'd like to make my own image class containing the image
and additional information (a lot of data, some Megabytes).
Then I'd like to transfer this object to another thread.
I tried to transfer an image over a queue and it works!
(see code below)
Is the data transferred or only a reference?
How could I hold the data global and transfer only a reference
that no data has to be copied (speed, memory)?
Thanks for any answer,
Markus
**************************************
import Image
import Queue
import thread
import time
class Send:
def __init__(self, queue, filename):
self.queue = queue
self.image = Image.open(filename, 'r')
def send(self):
self.queue.put(self.image)
class Recv:
def __init__(self, queue):
self.queue = queue
thread.start_new_thread(self.MyThread, (10,))
def MyThread(self, start):
while 1:
while not self.queue.empty():
img = self.queue.get()
img.save("result.bmp")
time.sleep(0.3)
msgq = Queue.Queue(0)
sender = Send(msgq, "test.bmp")
receiver = Recv(msgq)
sender.send()
time.sleep(2)