The "with" construct can't be used here. The lock needs to be held until writing to VOSpace is complete. This will have to be replaced with an "acquire" with a corresponding release after the file as been written to VOSpace. 

Fundamentally, the lock only needs to be held while the file is being written, but that would allow the possibility of a file in the queue being modified.