Fix file io exceptions and race conditions in api.py
Merge pull request #38 from umzegher/openfilelocked

Updates to api.py