Python: How to link a filename to a memory file

Viewed 123

What I want to realize has the following feature:

  1. Python program (or say process, thread,...) create a memory file that can be read or written.
  2. As long as the program is alive, the file data only exists in memory (NOT in disk). As long as the program is NOT alive, there is no date left.
  3. However there is an interface on the disk, it has a filename. This interface is linked to the memory file. Read and write operations on the interface are possible.

Why not use IO

The memory file will be an input of another program (not Python). So a file name is needed.

Why not use tempfile?

  1. The major reason is security. For different OS the finalization of tempfile will be different (right?) And for some occasional cases, such as interruptions on OS, data may remain on disk. So a program-holding data seems more secure (at least to an extent).
  2. Anyway I just want a try to see if tempfile can be avoided.
1 Answers

You could consider using a named pipe (using mkfifo). Another option is to create an actual file which the two programs open. Once both open it, you can unlink it so that it's no longer accessible on disk.

Related