473,404 Members | 2,178 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,404 software developers and data experts.

Queue limitations?

Hello,

I'm using Queue to send images from one thread to another, and some of
the images are not appearing in the consumer thread....maybe 1 in 3
arrive. I've tried passing the image data in both string form and as a
PIL Image object, with the same result.

It does work, however, if I use zlib to compress the image string
before passing it to Queue and then decompress it in the consumer
thread. So, my question: Does Queue have some capacity limitation?
(Uncompressed, my images are 786432 long... 512x512x3)

Here's a bit of the code:

# Producer --------
img = rayCaster.ReadTexture()
iq.put(img)
#iq.put(zlib.compress(img)) #this works fine

# End producer

# Consumer --------
class imageQueue(threading.Thread):

def __init__(self):
threading.Thread.__init__(self)
self.filenum = 0
self.theQueue = Queue.Queue(-1)

def run(self):
while 1:
# for testing, do something simple with images
img = self.theQueue.get()
imgt = Image.frombuffer('RGB',(512,512), img)
#imgt = Image.frombuffer('RGB',(512,512),
zlib.decompress(img)) #this one works
imgt.save( "./imgs_out/%i.png" % self.filenum, "PNG")
self.filenum += 1

def SetQueue(self, q_):
self.theQueue = q_
####
Thanks,
Matt

Mar 15 '06 #1
9 1541
ma****@gmail.com:
I'm using Queue to send images from one thread to another, and some of
the images are not appearing in the consumer thread....maybe 1 in 3
arrive.


I find that hard to believe. Could there be a bug in your program,
somewhere, somehow?

--
René Pijlman
Mar 15 '06 #2
ma****@gmail.com wrote:
I'm using Queue to send images from one thread to another, and some of
the images are not appearing in the consumer thread....maybe 1 in 3
arrive. I've tried passing the image data in both string form and as a
PIL Image object, with the same result.

It does work, however, if I use zlib to compress the image string
before passing it to Queue and then decompress it in the consumer
thread. So, my question: Does Queue have some capacity limitation?
(Uncompressed, my images are 786432 long... 512x512x3)
the queue holds references to the images, not the images themselves,
so the size should be completely irrelevant.
class imageQueue(threading.Thread):

def __init__(self):
threading.Thread.__init__(self)
self.filenum = 0
self.theQueue = Queue.Queue(-1)

def run(self):
while 1:
# for testing, do something simple with images
img = self.theQueue.get()
imgt = Image.frombuffer('RGB',(512,512), img)
#imgt = Image.frombuffer('RGB',(512,512), zlib.decompress(img)) #this one works
imgt.save( "./imgs_out/%i.png" % self.filenum, "PNG")
self.filenum += 1


how many instances of the imageQueue are you using ?

</F>

Mar 15 '06 #3
> the queue holds references to the images, not the images themselves,
so the size should be completely irrelevant.I use one instance of imageQueue.


hmmm.. true. And it also fails when I use PIL Image objects instead of
arrays. Any idea why compressing the string helps?

I'm using one instance of imageQueue.

-Thanks

Mar 15 '06 #4
ma****@gmail.com wrote:
the queue holds references to the images, not the images themselves,
so the size should be completely irrelevant.I use one instance of imageQueue.


hmmm.. true. And it also fails when I use PIL Image objects instead of
arrays. Any idea why compressing the string helps?


compression and decompression takes time. sounds like you have a timing
problem, and it's probably not in the imageQueue thread. adding a couple
of print statements to strategic locations (e.g push image, pop image, write
image to disk using this filename, etc) might help you sort this one out.

</F>

Mar 15 '06 #5
I should be able to add to the queue as fast as I want, right? I tried
adding time.sleep(.05) right after put(image) in the producer, and that
fixes it. There is only one thread producing and one thread consuming.

Thanks for the help.

Mar 15 '06 #6
ma****@gmail.com wrote:
the queue holds references to the images, not the images themselves,
so the size should be completely irrelevant.I use one instance of imageQueue.


hmmm.. true. And it also fails when I use PIL Image objects instead of
arrays. Any idea why compressing the string helps?

Compressing into a string converts the image intro a string type, which
is immutable. When you uncompress it, you've got a copy of the image,
rather than a reference to the original image. This might give you a
hint as to what is going wrong.

-Sw.

Mar 16 '06 #7
ma****@gmail.com wrote:
I should be able to add to the queue as fast as I want, right?
absolutely.

but if you slow the producer down, and you're only using one producer
and one consumer, the chance increases that the producer and the
consumer runs in perfect lockstep. you might as well *call* the con-
sumer from the producer...
I tried adding time.sleep(.05) right after put(image) in the producer,
and that fixes it. There is only one thread producing and one thread
consuming.


are you sure that the producer is creating new images, rather than
just pushing out references to the same data buffer ?

the frombuffer operation you're using in the client creates an image
object based on data in an external object; it does not copy the pixel
data. if the data in that buffer is changed by the producer, the image
seen by the consumer will change too.

</F>

Mar 16 '06 #8
I am creating the images by reading from texture memory using
glGetTexImage(). As an experiment, I tried calling glGetTexImage() only
once and letting imagQueue use that same reference over and over, but
the images were all the same.

So, this leads me to believe that the references returned by
glGetTexImage() are to unique buffers, right? ( documentation for
glGetTexImage() doesn't seem to disagree )

Perhaps, as an OpenGL program, something strange is happening with the
references when my producer method goes out of scope. I guess for now I
can be content to just pass immutable types across the thread boundary.

Mar 16 '06 #9
This example is missing a few initialization details although they can
possibly be inferred.
For example is
iq = imageQueue()
but imageQueue does not have a put() method.
Is SetQueue() called?
Is iq.start() called?

I like to see small, fully complete and tested examples.
The following works using strings as images.
It might prove interesting to modify this test case to use your image
objects instead of strings.

import Queue
import threading
import unittest

class imageQueue(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.filenum = 0
self.theQueue = Queue.Queue(-1)
self.done = False
self.results = []

def run(self):
while not self.done:
# for testing, do something simple with images
try:
img = self.theQueue.get(True, 1)
except:
pass
else:
self.results.append(img)
self.filenum += 1

def SetQueue(self, q_):
self.theQueue = q_

def stop(self):
self.done = True
class Tester(unittest.TestCase):
def setUp(self):
pass

def tearDown(self):
pass

def test_1(self):
# initialize
q = Queue.Queue()
iq = imageQueue()
iq.SetQueue(q)
iq.start()

# produce images
images = ["123", "456", "789"]
for x in images:
q.put(x)

# wait till all images consumed
while iq.filenum != 3:
pass

# stop the thread
iq.stop()

# assert that the consumer consumed what was produced
msg = "%s != %s" % (images, iq.results)
self.assert_(images == iq.results, msg)

if __name__ == '__main__':
unittest.main()

Mar 17 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: phil | last post by:
And sorry I got ticked, frustrating week >And I could help more, being fairly experienced with >threading issues and race conditions and such, but >as I tried to indicate in the first place,...
9
by: Brian Henry | last post by:
If i inherite a queue class into my class, and do an override of the enqueue member, how would i then go about actually doing an enqueue of an item? I am a little confused on this one... does over...
3
by: Kceiw | last post by:
Dear all, When I use #include "queue.h", I can't link it. The error message follows: Linking... G:\Projects\Datastructure\Queue\Debug\main.o(.text+0x136): In function `main':...
2
by: lavender | last post by:
When define a maxQueue is 10, means it able to store 10 items in circular queue,but when I key in the 10 items, it show "Queue Full" in items number 10. Where is the wrong in my code? Why it cannot...
3
by: jrpfinch | last post by:
I have a script which is based on the following code. Unfortunately, it only works on Python 2.3 and not 2.5 because there is no esema or fsema attribute in the 2.5 Queue. I am hunting through...
4
by: j_depp_99 | last post by:
Thanks to those guys who helped me out yesterday. I have one more problem; my print function for the queue program doesnt work and goes into an endless loop. Also I am unable to calculate the...
0
by: ecestd | last post by:
I did implement the copy constructor but still have a problem with it. It is not working. What could be wrong? #include "QueueP.h" #include <cassert // for assert #include <new // for...
9
by: Martin DeMello | last post by:
I'm writing a cluster monitor, that collects information from a set of machines and logs it to a database In the interests of not hammering the db unnecessarily, I'm considering the following...
2
by: vaclavpich | last post by:
Hi all, I want to now your opinion on interface of my priority_queue. I now std has very good a priority_queue. But I couldn't use std. So I had to write my....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.