2

I'm trying to write a small wsgi application which will put some objects to an external queue after each request. I want to make this in batch, ie. make the webserver put the object to a buffer-like structure in memory, and another thread and/or process for sending these objects to the queue in batch, when buffer is big enough or after certain timeout, and clearing the buffer. I don't want to be in NIH syndrome and not want to bother with threading stuff, however I could not find a suitable code for this job. Any suggestions?

3 Answers 3

8

Examine https://docs.python.org/library/queue.html to see if it meets your needs.

Sign up to request clarification or add additional context in comments.

4 Comments

beat me by 16 seconds to the same answer. I think that's what he wants too, but couldn't quite figure it out.
Here is what I like most about Python: the 80% of what you're going to implement is already out there. Often, even in the standard library.
And this question has already been asked on SO. stackoverflow.com/questions/394500/…
I know this is a 5-year old thread, but apparently still relevant (since I just found it looking for a buffer-like structure in Python)... I wanted to report that the above link to python.org is no longer valid if anyone cares to update it, if possible. I did find pymotw.com/2/Queue as a possible replacement.
3

Since you write "thread and/or process", see also multiprocessing.Queue and multiprocessing.JoinableQueue from 2.6. Those are interprocess variants of Queue.

Comments

1

Use a buffered stream if you are using python 3.0.

1 Comment

Look like it's available for Python 2 as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.