Skip to content

Instantly share code, notes, and snippets.

@monsterxx03
Last active February 11, 2019 04:09
Show Gist options
  • Save monsterxx03/3d2daef3d9add57d697d95c51a5266b2 to your computer and use it in GitHub Desktop.
Save monsterxx03/3d2daef3d9add57d697d95c51a5266b2 to your computer and use it in GitHub Desktop.
test for celery memory leak
import resource
import gc
from celery import Celery
app = Celery()
app.conf.update(BROKER_URL='redis://localhost:6379/1')
@app.task
def dummy():
return '1'
def print_mem():
print 'Memory usage: %s (kb)' % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
def run():
for i in range(10000):
dummy.delay()
if i % 1000 == 0:
print_mem()
run()
print gc.garbage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment