In my application, I need to look at the directory for new files. The volume of traffic is very large, and at least hundreds of new files per second will appear. I am currently using a busy cycle with this idea:
while True:
time.sleep(0.2)
if len(os.listdir('.')) > 0:
After completing the profiling, I see a lot of time spent in a dream, and I wonder if I should change this to use the survey instead.
I'm trying to use one of the available classes in selectto poll my directory, but I'm not sure if it really works, or if I'm just doing it wrong.
I get fd for my directory with:
fd = os.open('.', os.O_DIRECT)
Then I tried several methods to see when the directory changes. For example, one of my attempts:
poll = select.poll()
poll.register(fd, select.POLLIN)
poll.poll()
os.read(fd, 4096)
poll.poll()
os.read(fd, 4096)
poll() , ? , , - .
?
, while True: look for changes?