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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Roque
slapos
Commits
9860b7dc
Commit
9860b7dc
authored
Oct 27, 2011
by
Antoine Catton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove any time.sleep() from execute. Use inotify instead.
parent
0940ba76
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
22 deletions
+42
-22
slapos/recipe/librecipe/execute.py
slapos/recipe/librecipe/execute.py
+42
-22
No files found.
slapos/recipe/librecipe/execute.py
View file @
9860b7dc
...
...
@@ -4,6 +4,46 @@ import signal
import
subprocess
import
time
import
inotifyx
def
_wait_files_creation
(
file_list
):
# Etablish a list of directory and subfiles
directories
=
dict
()
for
dirname
,
filename
in
[
os
.
path
.
split
(
f
)
for
f
in
file_list
]:
directories
.
setdefault
(
dirname
,
dict
())
directories
[
dirname
][
filename
]
=
False
def
all_files_exists
():
return
all
([
all
(
files
.
values
())
for
files
in
directories
.
values
()])
fd
=
inotifyx
.
init
()
try
:
# Watch every directories where the file are
watchdescriptors
=
dict
()
for
dirname
in
directories
.
keys
():
wd
=
inotifyx
.
add_watch
(
fd
,
dirname
,
inotifyx
.
IN_CREATE
|
inotifyx
.
IN_DELETE
)
watchdescriptors
[
wd
]
=
dirname
# Set to True the file wich exists
for
dirname
,
filename
in
[
os
.
path
.
split
(
f
)
for
f
in
file_list
]:
directories
[
dirname
][
filename
]
=
os
.
path
.
exists
(
os
.
path
.
join
(
dirname
,
filename
))
# Let's wait for every file creation
while
not
all_files_exists
():
events_list
=
inotifyx
.
get_events
(
fd
)
for
event
in
events_list
:
dirname
=
watchdescriptors
[
event
.
wd
]
if
event
.
name
in
directories
[
dirname
]:
# One of watched file was created or deleted
if
event
.
mask
&
inotifyx
.
IN_DELETE
:
directories
[
dirname
][
event
.
name
]
=
False
else
:
directories
[
dirname
][
event
.
name
]
=
True
finally
:
os
.
close
(
fd
)
def
execute
(
args
):
"""Portable execution with process replacement"""
...
...
@@ -14,18 +54,7 @@ def execute_wait(args):
"""Execution but after all files in args[1] exists"""
exec_list
=
list
(
args
[
0
])
file_list
=
list
(
args
[
1
])
sleep
=
60
while
True
:
ready
=
True
for
f
in
file_list
:
if
not
os
.
path
.
exists
(
f
):
print
'File %r does not exists, sleeping for %s'
%
(
f
,
sleep
)
ready
=
False
if
ready
:
break
# XXX: It's the same as ../ca/certificate_authoritiy.py
# We should use pyinotify as well. Or select() on socket.
time
.
sleep
(
sleep
)
_wait_files_creation
(
file_list
)
os
.
execv
(
exec_list
[
0
],
exec_list
+
sys
.
argv
[
1
:])
...
...
@@ -49,16 +78,7 @@ def executee_wait(args):
env
=
os
.
environ
.
copy
()
for
k
,
v
in
environment
.
iteritems
():
env
[
k
]
=
v
sleep
=
60
while
True
:
ready
=
True
for
f
in
file_list
:
if
not
os
.
path
.
exists
(
f
):
print
'File %r does not exists, sleeping for %s'
%
(
f
,
sleep
)
ready
=
False
if
ready
:
break
time
.
sleep
(
sleep
)
_wait_files_creation
(
file_list
)
os
.
execve
(
exec_list
[
0
],
exec_list
+
sys
.
argv
[
1
:],
env
)
def
sig_handler
(
signal
,
frame
):
...
...
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