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
Lu Xu
slapos.toolbox
Commits
48c936ba
Commit
48c936ba
authored
Apr 15, 2017
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
promise.is_process_older_than_dependency_set: Define max file limit to walk, to prevent over call
parent
5d15d62a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
slapos/promise/is_process_older_than_dependency_set/__init__.py
.../promise/is_process_older_than_dependency_set/__init__.py
+9
-4
No files found.
slapos/promise/is_process_older_than_dependency_set/__init__.py
View file @
48c936ba
...
@@ -17,7 +17,8 @@ import psutil
...
@@ -17,7 +17,8 @@ import psutil
ignored_extension_set
=
set
([
".pyc"
])
ignored_extension_set
=
set
([
".pyc"
])
def
moduleIsModifiedSince
(
top
,
since
,
followlinks
=
False
):
def
moduleIsModifiedSince
(
top
,
since
,
followlinks
=
False
,
file_limit
=
100
):
file_count
=
0
for
root
,
dir_list
,
file_list
in
os
.
walk
(
top
,
followlinks
=
followlinks
):
for
root
,
dir_list
,
file_list
in
os
.
walk
(
top
,
followlinks
=
followlinks
):
if
root
==
top
:
if
root
==
top
:
continue
continue
...
@@ -25,6 +26,9 @@ def moduleIsModifiedSince(top, since, followlinks=False):
...
@@ -25,6 +26,9 @@ def moduleIsModifiedSince(top, since, followlinks=False):
del
dir_list
[:]
del
dir_list
[:]
continue
continue
for
name
in
file_list
:
for
name
in
file_list
:
file_count
+=
1
if
file_count
>=
file_limit
:
raise
ValueError
(
"%s exceeded the file limit of %s file"
%
(
top
,
file_limit
))
_
,
ext
=
os
.
path
.
splitext
(
name
)
_
,
ext
=
os
.
path
.
splitext
(
name
)
if
ext
in
ignored_extension_set
:
if
ext
in
ignored_extension_set
:
continue
continue
...
@@ -36,10 +40,10 @@ def moduleIsModifiedSince(top, since, followlinks=False):
...
@@ -36,10 +40,10 @@ def moduleIsModifiedSince(top, since, followlinks=False):
return
True
return
True
return
False
return
False
def
isProcessOlderThanDependencySet
(
pid
,
python_path_list
,
kill
=
False
):
def
isProcessOlderThanDependencySet
(
pid
,
python_path_list
,
kill
=
False
,
limit
=
100
):
process
=
psutil
.
Process
(
pid
)
process
=
psutil
.
Process
(
pid
)
start_time
=
process
.
create_time
()
start_time
=
process
.
create_time
()
if
any
(
moduleIsModifiedSince
(
product_path
,
start_time
)
for
product_path
in
python_path_list
):
if
any
(
moduleIsModifiedSince
(
product_path
,
start_time
,
file_limit
=
limit
)
for
product_path
in
python_path_list
):
if
kill
:
if
kill
:
print
"Terminating process %s with pid %s"
%
(
process
.
name
(),
pid
)
print
"Terminating process %s with pid %s"
%
(
process
.
name
(),
pid
)
process
.
terminate
()
process
.
terminate
()
...
@@ -54,12 +58,13 @@ def isProcessFromPidFileOlderThanDependencySet(pid_file_path, python_path_list,
...
@@ -54,12 +58,13 @@ def isProcessFromPidFileOlderThanDependencySet(pid_file_path, python_path_list,
def
main
():
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"-k"
,
"--kill"
,
action
=
"store_true"
)
parser
.
add_argument
(
"-k"
,
"--kill"
,
action
=
"store_true"
)
parser
.
add_argument
(
"-l"
,
"--limit"
,
default
=
100
)
parser
.
add_argument
(
"pid_file_path"
,
metavar
=
"PID_FILE"
)
parser
.
add_argument
(
"pid_file_path"
,
metavar
=
"PID_FILE"
)
parser
.
add_argument
(
"python_path_list"
,
nargs
=
"*"
,
metavar
=
"ADDITIONAL_PYTHON_PATH"
,
default
=
[])
parser
.
add_argument
(
"python_path_list"
,
nargs
=
"*"
,
metavar
=
"ADDITIONAL_PYTHON_PATH"
,
default
=
[])
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
try
:
try
:
if
isProcessFromPidFileOlderThanDependencySet
(
args
.
pid_file_path
,
sys
.
path
+
args
.
python_path_list
,
kill
=
args
.
kill
):
if
isProcessFromPidFileOlderThanDependencySet
(
args
.
pid_file_path
,
sys
.
path
+
args
.
python_path_list
,
kill
=
args
.
kill
,
limit
=
args
.
limit
):
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