-
-
Save leetreveil/f36e3ff998e64cce44ee0bb21b7cbcce to your computer and use it in GitHub Desktop.
APIStar 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 tracemalloc | |
from apistar import App, Route, http | |
tracemalloc.start(1) | |
snapshot1 = tracemalloc.take_snapshot() | |
def welcome(): | |
snapshot2 = tracemalloc.take_snapshot() | |
top_stats = snapshot2.compare_to(snapshot1, 'lineno') | |
print("[ Top 10 differences ]") | |
for stat in top_stats[:10]: | |
print(stat) | |
return {'message': 'Welcome to API Star!'} | |
class LeakingHook: | |
def on_request(self, req: http.Request): | |
pass | |
routes = [ | |
Route('/', method='GET', handler=welcome) | |
] | |
app = App(routes=routes, event_hooks=[LeakingHook]) | |
if __name__ == '__main__': | |
app.serve('127.0.0.1', 5000) |
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 tracemalloc | |
from apistar import App, Route, http | |
tracemalloc.start(25) | |
snapshot1 = tracemalloc.take_snapshot() | |
def welcome(): | |
global snapshot1 | |
snapshot2 = tracemalloc.take_snapshot() | |
top_stats = snapshot2.compare_to(snapshot1, 'traceback') | |
stat = top_stats[0] | |
print("%s memory blocks: %.1f KiB" % (stat.count, stat.size / 1024)) | |
for line in stat.traceback.format(): | |
print(line) | |
snapshot1 = snapshot2 | |
return {'message': 'Welcome to API Star!'} | |
class LeakingHook: | |
def on_request(self, req: http.Request): | |
pass | |
routes = [ | |
Route('/', method='GET', handler=welcome) | |
] | |
app = App(routes=routes, event_hooks=[LeakingHook]) | |
if __name__ == '__main__': | |
app.serve('127.0.0.1', 5000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment