Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
105
Merge Requests
105
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos
Commits
00ebaac8
Commit
00ebaac8
authored
Jan 19, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
librecipe/inotify: fallback to polling when adding inotify watch fail
parent
ea0e89b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
slapos/recipe/librecipe/inotify.py
slapos/recipe/librecipe/inotify.py
+16
-2
No files found.
slapos/recipe/librecipe/inotify.py
View file @
00ebaac8
...
...
@@ -24,9 +24,14 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import
logging
import
os
import
time
from
inotify_simple
import
INotify
,
flags
logger
=
logging
.
getLogger
(
__name__
)
def
subfiles
(
directory
):
"""Return the list of subfiles of a directory, and wait for the newly created
ones.
...
...
@@ -35,10 +40,19 @@ def subfiles(directory):
ALWAYS ITERATE OVER IT !!!*"""
with
INotify
()
as
inotify
:
inotify
.
add_watch
(
directory
,
flags
.
CLOSE_WRITE
|
flags
.
MOVED_TO
)
try
:
inotify
.
add_watch
(
directory
,
flags
.
CLOSE_WRITE
|
flags
.
MOVED_TO
)
inotify_available
=
True
except
OSError
:
logger
.
warning
(
"Unable to add inotify watch, falling back to polling"
)
inotify_available
=
False
names
=
os
.
listdir
(
directory
)
while
True
:
for
name
in
names
:
yield
os
.
path
.
join
(
directory
,
name
)
names
=
(
event
.
name
for
event
in
inotify
.
read
())
if
inotify_available
:
names
=
(
event
.
name
for
event
in
inotify
.
read
())
else
:
time
.
sleep
(
5
)
names
=
os
.
listdir
(
directory
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment