fix race condition with try except