Haldun
Haldun

Reputation: 1285

Implementing a buffer-like structure in Python

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?

Upvotes: 2

Views: 3773

Answers (3)

S.Lott
S.Lott

Reputation: 391952

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

Upvotes: 8

nosklo
nosklo

Reputation: 223062

Use a buffered stream if you are using python 3.0.

Upvotes: 1

Constantin
Constantin

Reputation: 28184

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

Upvotes: 3

Related Questions