Skip to content

Instantly share code, notes, and snippets.

@beltran
Created April 13, 2017 23:04
Show Gist options
  • Save beltran/bfc8aeb8160e944f5c897e0e1f37691d to your computer and use it in GitHub Desktop.
Save beltran/bfc8aeb8160e944f5c897e0e1f37691d to your computer and use it in GitHub Desktop.
import time
import concurrent.futures
import resource
from guppy import hpy
import weakref
class Object:
pass
class BigObject(object):
def __init__(self):
weaked_my_stuff = [Object()] * 10000000 * 10000000
self.my_stuff = weaked_my_stuff
self.weaked_my_stuff = weakref.ref(weaked_my_stuff)
def cosume_memory():
reserve = [BigObject()] * 10000
r = weakref.ref(reserve)
for el in reserve:
el.my_stuff = None
num_threads = 50
pool = concurrent.futures.ThreadPoolExecutor(max_workers=num_threads)
hp = hpy()
for i in range(50):
for i in range(num_threads):
pool.submit(cosume_memory)
print(resource.getrusage(resource.RUSAGE_SELF))
print("Waiting for pool to finish (this may take a while)")
pool.shutdown(wait=True)
print("\n\n\n\n======Finished the loop==========")
while 1:
print(resource.getrusage(resource.RUSAGE_SELF))
print(hp.heap())
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment