I stumbled upon unintuitive problem: if you recursively glob (with pathlib) fast-changing directory, where other directories are created and deleted, you have a chance to get FileNotFoundException. If directory is not found, then why bother me with this? Why not just skip bogus directory and continue? And how i can get around this in a compact way?
Here is how to reproduce this:
Launch one terminal with this sh command
while true; do mkdir deleteme && rmdir deleteme; done
and another with this python script:
from pathlib import Path
p = Path()
while True:
list(p.rglob('*'))
or, as oneliner:
while true; do mkdir 1 && rmdir 1; done & python3 -c "from pathlib import Path; from itertools import count; p = Path(); [list(p.rglob('*')) for i in count(start=1)]"; fg