Skip to content

Instantly share code, notes, and snippets.

@leetreveil
Last active August 13, 2018 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leetreveil/f36e3ff998e64cce44ee0bb21b7cbcce to your computer and use it in GitHub Desktop.
Save leetreveil/f36e3ff998e64cce44ee0bb21b7cbcce to your computer and use it in GitHub Desktop.
APIStar Memory Leak
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)
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