Skip to content

Instantly share code, notes, and snippets.

@sweenzor
Created December 26, 2011 23:35
Show Gist options
  • Save sweenzor/1522293 to your computer and use it in GitHub Desktop.
Save sweenzor/1522293 to your computer and use it in GitHub Desktop.
Investigating memory using of python Queues
#!/usr/bin/env python
import Queue
import json
import random
import time
import psutil
def random_message():
"""create a dict of junk data, return as json"""
msg = {}
for i in range(9):
msg[random.random()] = random.random()
return json.dumps(msg)
q = Queue.LifoQueue()
counter = 0
while True:
counter += 1
q.put(random_message())
time.sleep(0.01)
if counter % 1000 == 0:
print 'queue size', q.qsize()
print psutil.phymem_usage()
print '\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment