In Python I open a temporary file for write by using tempfile.mkstemp in order to be sure that the file is destroyed when released (even if application crashes).
Now I need to pass this file to another application but this application is not going to be able to open the file as long the file is opened for write.
Can I change the access mode or reopen the file without changing the file handle in order to prevent it from being deleted too soon?
Update: opening the file in read mode does not solve the problem, the file must be opened in shared mode.
There is no documented way to switch the file modes (r, w, a) for an open file.
Instead of TempFile, consider using mmap to share data between programs.