470,811 Members | 1,124 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,811 developers. It's quick & easy.

queue for large objects, object references


in a data acquisition program I have several threads,
one thread grabbing images and another doing some
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,


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):

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()

msgq = Queue.Queue(0)

sender = Send(msgq, "test.bmp")
receiver = Recv(msgq)

Jul 18 '05 #1
1 1677
> Is the data transferred or only a reference?

Everything in Python can be thought of as passed by reference. This
will mean different things to different people, which is why you should
look at these examples.

def funct(i): .... i += 1
.... k = 8
k 8

The integer doesn't get updated, because integers are immutable.

def funct(l): .... l = []
.... k = [1,2,3]
k [1, 2, 3]

Pointing the name 'l' to a new list object, doesn't change the object
that 'k' points to.

def funct(l): .... l[:] = []
.... k = [4,5,6]


The list only gets updated when you actually modify the list pointed to
by the list named 'l'.
There are literally hundreds more examples I could go through. I'll let
you try to figure a few of those out.

- Josiah
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Richard Townsend | last post: by
1 post views Thread by Ross Johnson | last post: by
6 posts views Thread by Mountain Bikn' Guy | last post: by
5 posts views Thread by Tim Marsden | last post: by
21 posts views Thread by ajbecker | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.