Created
May 16, 2019 16:38
-
-
Save ofek/6264f64fc6bbcb3f2af48a45fe0b9caa 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
import multiprocessing | |
import os | |
import psutil | |
pid = os.getpid() | |
p = psutil.Process(pid) | |
def _yaml_load(config): | |
import yaml | |
return yaml.safe_load(config) | |
def yaml_load(config): | |
with multiprocessing.Pool(1) as pool: | |
print_mem('pre-access') | |
return pool.apply(_yaml_load, args=(config,)) | |
def print_mem(when): | |
mem = p.memory_info()[0] / (2 ** 20) | |
print('Memory {}: {} MiB'.format(when, mem)) | |
def main(): | |
config = 'instances:\n- tags:\n - foo:bar' | |
result = yaml_load(config) | |
print_mem('post-access') | |
print('Loaded: {}'.format(result)) | |
import yaml | |
print_mem('on real import') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment