On 16 November 2015 at 23:38, Paul Moore <p.f.mo...@gmail.com> wrote:
> (I don't know what Unix does, I suspect it retains an old
> copy of the shared library for the process until the process exists,
> in which case you'd see a different issue, that you do an upgrade, but
> your process still uses the old code till you restart).

Marius explained the lower level technical details, but the relevant
API at the Python level is the "fileno()" method on file-like objects:
once you have a file descriptor, you can access the kernel object
representing the open file directly, and the kernel doesn't care if
the original filesystem path has been remapped to refer to something
else. The persistent identifier at the filesystem level is the inode
number, rather than the filesystem path.

After opening a file, the inode numbers match:

>>> f = open("example", "w")
>>> os.stat("example").st_ino
244985
>>> os.stat(f.fileno()).st_ino
244985

The filesystem's reference to the inode can be dropped, without losing
the kernel's reference:

>>> os.remove("example")
>>> os.stat("example").st_ino
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'example'
>>> os.stat(f.fileno()).st_ino
244985

The original filesystem path can then be mapped to a new inode:

>>> f2 = open("example", "w")
>>> os.stat("example").st_ino
242960
>>> os.stat(f.fileno()).st_ino
244985
>>> os.stat(f2.fileno()).st_ino
242960

As Wayne noted, the fact shared libraries can be overwritten while
processes are using them is then just an artifact of this general
property of *nix style filesystem access.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Distutils-SIG maillist  -  Distutils-SIG@python.org
https://mail.python.org/mailman/listinfo/distutils-sig

Reply via email to