Skip to content

Instantly share code, notes, and snippets.

@ofek

ofek/invoke_yaml.py

Created May 16, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.