Skip to content

Instantly share code, notes, and snippets.

@ofek
Created May 16, 2019 16:38
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 ofek/6264f64fc6bbcb3f2af48a45fe0b9caa to your computer and use it in GitHub Desktop.
Save ofek/6264f64fc6bbcb3f2af48a45fe0b9caa to your computer and use it in GitHub Desktop.
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