dsoprea / PyInotify

An efficient and elegant inotify (Linux filesystem activity monitor) library for Python. Python 2 and 3 compatible.
GNU General Public License v2.0
242 stars 73 forks source link

AttributeError: 'Inotify' object has no attribute '_Inotify__inotify_fd' #91

Open to7m opened 3 years ago

to7m commented 3 years ago

OS: Arch Linux Python version: 3.9.1

Originally noticed here: https://github.com/dsoprea/PyInotify/issues/90, and now I can reproduce it.

The AttributeError keeps popping up, for example in del:

File "/home/to7m/.local/lib/python3.9/site-packages/inotify/adapters.py", line 79, in __del__
    os.close(self.__inotify_fd)
AttributeError: 'Inotify' object has no attribute '_Inotify__inotify_fd'

On my system, the following code reproduces the problem consistently:

from multiprocessing import Process
from inotify.adapters import Inotify
from time import sleep

def proc():
    inotify_obj = Inotify()
    sleep(60)

process_count = 1000
for _ in range(process_count):
    Process(target=proc).start()

It may be necessary to increase process_count on other systems to expose the bug.

to7m commented 3 years ago

Related: As other issue reports suggest, I think a context manager might help in general.