Created
September 10, 2018 19:15
-
-
Save Somewater/40d7a808d1efd7b2c77f22f8bcb73553 to your computer and use it in GitHub Desktop.
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
## prepare as: | |
# conda create -n py37 -c anaconda python=3.7 | |
# source activate py37 | |
# python --version | |
# python py37_gc_freeze_test.py | |
from multiprocessing import Process | |
import gc | |
import time | |
a = None | |
def foo(): | |
print('worker started') | |
time.sleep(5) | |
s = 0 | |
for it in range(100): | |
for i in a: | |
s += i | |
print("%d) s=%d" % (it, s)) | |
if __name__ == '__main__': | |
gc.freeze() | |
a = [] | |
for i in range(50000000): | |
a.append(i**2) | |
print('a construncted, %d freezed objects' % gc.get_freeze_count()) | |
time.sleep(5) | |
processes = [] | |
for i in range(8): | |
p = Process(target=foo, args=()) | |
p.start() | |
processes.append(p) | |
for p in processes: | |
p.join() | |
print('process completed') | |
print('all processes completed') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment