473,379 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

queue for large objects, object references

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)
Jul 18 '05 #1
1 2115
> 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
funct(k)
k 8

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

def funct(l): .... l = []
.... k = [1,2,3]
funct(k)
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]
funct(k)
k

[]

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: WinstonSmith | last post by:
Hello everyone, I got a problem about GC when creating large fields (some MB), set reference to null and call GC.Collect. Not all virtual mem is released. Situation improved in .net 1.1 but not...
4
by: Richard Townsend | last post by:
I've been experimenting putting a reference to a function into a Queue object and was wondering what actually gets put in the Queue - is it the function's code object? If I read from the Queue...
1
by: Ross Johnson | last post by:
Hi, I'm moving a database from 7.0.2 to 7.3.3. The db contains several thousand large objects that I need to export. To do this I've managed to modify the contrib/pg_dumplo utility from 7.3.3...
6
by: Mountain Bikn' Guy | last post by:
What is the C# equivalent to calling PostMessage() in Win32 in order for an object to queue a message to itself? Thanks Mountain
5
by: Tim Marsden | last post by:
HI, I am developing a application in vb.net. I split down my functionality into several separate DLL's. The solution is becoming very large, nearly 100 projects, each project a dll's. There is...
21
by: ajbecker | last post by:
I'm trying to debug a problem I'm having where my finalizer queue is getting filled up faster than the thread can execute them, (or at least I think that's what's going on.) Is there a way that I...
7
by: copx | last post by:
How do you implement an event queue in C? The problem I had is that events needed pointers to the objects they affect and I do not know any way to check if pointers are actually valid in C. The...
0
by: april86 | last post by:
Hello everyone! I am new to C# and i have a question: I need to copy one Queue to another and i tried this: public static void copyQueues(Queue q, Queue q_copy) { Array...
2
by: manojmohadikar2008 | last post by:
Hi All, We are observing a serious issue with the memory usage of Queue and its very critical issue which needs to be fixed. We have an application which runs two threads i.e. a Producer and a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.