Skip to content

Instantly share code, notes, and snippets.

@mattbennett
Last active May 1, 2017 10:01
Show Gist options
  • Save mattbennett/50509277a33c43658fe3fffa445f4a0a to your computer and use it in GitHub Desktop.
Save mattbennett/50509277a33c43658fe3fffa445f4a0a to your computer and use it in GitHub Desktop.
Eventlet memory leak
import eventlet
import eventlet.debug
eventlet.debug.hub_exceptions(False)
import objgraph
import gc
import uuid
threads = {}
class Foo(object):
def __init__(self, ident):
self.thread = threads[ident]
def target(ident):
foo = Foo(ident)
raise Exception("boom")
def status():
while True:
gc.collect()
print("Foo count: ", objgraph.count('Foo'))
print("GreenThread count: ", objgraph.count('eventlet.greenthread.GreenThread'))
print("Active thread count: "len(threads))
eventlet.sleep(5)
def cleanup(gt, ident):
del threads[ident]
eventlet.spawn_n(status)
while True:
ident = uuid.uuid4()
gt = eventlet.spawn(target, ident)
gt.link(cleanup, ident)
threads[ident] = gt
eventlet.sleep(.1)
eventlet
objgraph
import eventlet
import eventlet.debug
eventlet.debug.hub_exceptions(False)
import objgraph
import gc
threads = {}
class Foo(object):
def __init__(self, index):
self.thread = threads[index]
def target(index):
foo = Foo(index)
if index % 2 == 0:
raise Exception("boom")
for index in range(10):
gt = eventlet.spawn(target, index)
threads[index] = gt
eventlet.sleep()
del threads
gc.collect()
print("Foo count: ", objgraph.count('Foo'))
print("GreenThread count: ", objgraph.count('eventlet.greenthread.GreenThread'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment