Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Klaus Wölfel
slapos.toolbox
Commits
4da475b3
Commit
4da475b3
authored
Feb 26, 2016
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add option in is-process-older-than-dependency-set to kill
the process if older than dependency set.
parent
d164fab3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
7 deletions
+18
-7
slapos/promise/is_process_older_than_dependency_set/__init__.py
.../promise/is_process_older_than_dependency_set/__init__.py
+18
-7
No files found.
slapos/promise/is_process_older_than_dependency_set/__init__.py
View file @
4da475b3
...
@@ -11,6 +11,7 @@ process.
...
@@ -11,6 +11,7 @@ process.
import
sys
import
sys
import
os
import
os
import
errno
import
errno
import
argparse
import
psutil
import
psutil
...
@@ -31,19 +32,29 @@ def moduleIsModifiedSince(top, since, followlinks=False):
...
@@ -31,19 +32,29 @@ def moduleIsModifiedSince(top, since, followlinks=False):
return
True
return
True
return
False
return
False
def
isProcessOlderThanDependencySet
(
pid
,
python_path_list
):
def
isProcessOlderThanDependencySet
(
pid
,
python_path_list
,
kill
=
False
):
start_time
=
psutil
.
Process
(
pid
).
create_time
()
process
=
psutil
.
Process
(
pid
)
return
any
(
moduleIsModifiedSince
(
product_path
,
start_time
)
for
product_path
in
python_path_list
)
start_time
=
process
.
create_time
()
if
any
(
moduleIsModifiedSince
(
product_path
,
start_time
)
for
product_path
in
python_path_list
):
if
kill
:
process
.
terminate
()
return
True
return
False
def
isProcessFromPidFileOlderThanDependencySet
(
pid_file_path
,
python_path_list
):
def
isProcessFromPidFileOlderThanDependencySet
(
pid_file_path
,
python_path_list
,
kill
=
False
):
with
open
(
pid_file_path
,
"r"
)
as
f
:
with
open
(
pid_file_path
,
"r"
)
as
f
:
pid
=
int
(
f
.
readline
())
pid
=
int
(
f
.
readline
())
return
isProcessOlderThanDependencySet
(
pid
,
python_path_list
)
return
isProcessOlderThanDependencySet
(
pid
,
python_path_list
,
kill
=
kill
)
def
main
():
def
main
():
pid_file_path
,
additional_python_path
=
sys
.
argv
[
1
],
sys
.
argv
[
2
:]
if
len
(
sys
.
argv
)
>
2
else
[]
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"-k"
,
"--kill"
,
action
=
"store_true"
)
parser
.
add_argument
(
"pid_file_path"
,
metavar
=
"PID_FILE"
)
parser
.
add_argument
(
"python_path_list"
,
nargs
=
"*"
,
metavar
=
"ADDITIONAL_PYTHON_PATH"
,
default
=
[])
args
=
parser
.
parse_args
()
try
:
try
:
if
isProcessFromPidFileOlderThanDependencySet
(
pid_file_path
,
sys
.
path
+
additional_python_path
):
if
isProcessFromPidFileOlderThanDependencySet
(
args
.
pid_file_path
,
sys
.
path
+
args
.
python_path_list
,
kill
=
args
.
kill
):
return
1
return
1
return
0
return
0
except
(
OSError
,
IOError
)
as
err
:
except
(
OSError
,
IOError
)
as
err
:
...
...
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