Last active
May 1, 2017 10:01
-
-
Save mattbennett/50509277a33c43658fe3fffa445f4a0a to your computer and use it in GitHub Desktop.
Eventlet memory leak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eventlet | |
objgraph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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