recovered code from review/jamhed/pr/yaml-atomic-write

Recovered code from @jamhed to get atomic_write on sessions. Not sure its relevance, but still, here it is. Please vote for it :-)