Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
prunner
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rx-etersoft
prunner
Commits
3fa8ee35
Commit
3fa8ee35
authored
Mar 15, 2018
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added option '--run-after' ('-a') for run programs after main process terminated
parent
874ead4e
Pipeline
#1258
failed with stage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
8 deletions
+35
-8
README.md
README.md
+8
-0
prunner
bin/prunner
+27
-8
No files found.
README.md
View file @
3fa8ee35
...
...
@@ -18,6 +18,7 @@ Help
-d | --run-from-dir dir - run programs from directory
-f | --run-from-file file - run programs from file
-r | --run '
[
params
]
prog args..' - run programs from command line"
-a | --run-after 'prog args..' - run programs after main process terminated"
-p | --monitor-pid pid - pid of main process (for monitoring)
-v | --verbose - Print info messages
-V | --version - Version info
...
...
@@ -90,3 +91,10 @@ Example 4
---------
prunner -p PID -d ./child.d -f runlist.txt -r '
[
restart=2
]
prog1 arg1 arg2'
Т.е. можно указывать и каталог и файл и -r одновременно
Example 5
---------
prunner -p PID -d ./child.d --run-after 'prog_after_term arg1 arg2'
В этом примере запустяться программы из каталога
*child.d*
, а после того
как процесс PID завершится, запустится программа
*'prog_after_term'*
Параметр
*--run-after*
или
*-a*
можно указывать многократно.
bin/prunner
View file @
3fa8ee35
...
...
@@ -188,15 +188,22 @@ def do_check_alive(childs):
term_check_alive
.
wait
(
check_alive_period
)
def
do_monitoring
(
main_pid
,
run_list
,
not_monit
):
def
do_run_after
(
run_list
):
for
p
in
run_list
:
p
.
run
()
def
do_monitoring
(
main_pid
,
run_list
,
not_monit
,
run_after_list
):
"""
Running processes and monitoring
:param main_pid: pid for monitoring
:param run_list: list of process for run
:param not_monit: True - disable monitoring (only run process)
:param run_after: True - run programs after main process terminated
:return: None
"""
proc_list
=
list
()
interrupted
=
False
for
p
in
run_list
:
if
p
.
run
():
proc_list
.
append
(
p
)
...
...
@@ -204,13 +211,18 @@ def do_monitoring(main_pid, run_list, not_monit):
terminate_all_process
(
proc_list
)
exit
(
1
)
check_alive_thread
=
threading
.
Thread
(
target
=
do_check_alive
,
args
=
(
proc_list
,))
check_alive_thread
=
None
if
len
(
proc_list
)
>
0
:
check_alive_thread
=
threading
.
Thread
(
target
=
do_check_alive
,
args
=
(
proc_list
,))
try
:
if
not_monit
:
return
term_check_alive
.
clear
()
check_alive_thread
.
start
()
if
check_alive_thread
:
check_alive_thread
.
start
()
monit_process
=
psutil
.
Process
(
main_pid
)
while
not
term_check_alive
.
is_set
():
try
:
...
...
@@ -220,14 +232,19 @@ def do_monitoring(main_pid, run_list, not_monit):
pass
except
(
KeyboardInterrupt
,
SystemExit
):
pass
interrupted
=
True
finally
:
term_check_alive
.
set
()
if
check_alive_thread
.
is_alive
():
if
check_alive_thread
and
check_alive_thread
.
is_alive
():
check_alive_thread
.
join
()
terminate_all_process
(
proc_list
)
# run programs after teminated
if
not
interrupted
and
len
(
run_after_list
)
>
0
:
log_info
(
"run programms after terminated main process..."
)
do_run_after
(
run_after_list
)
def
terminate_all_process
(
proc_list
):
"""
...
...
@@ -357,10 +374,11 @@ def read_from_commandline(param):
def
usage
():
print
"[-p|--monitor-pid] pid - pid of main process (for monitoring)"
print
"[-d|--run-from-dir] dir - run programs from directory"
print
"[-f|--run-from-file] file - run programs from file"
print
"[-r|--run] '[params]prog args..' - run programs from command line"
print
"[-
p|--monitor-pid] pid - pid of main process (for monitoring)
"
print
"[-
a|--run-after] 'prog args..' - run programs after main process terminated
"
print
"[-v|--verbose] - Print info messages"
print
"[-V|--version] - Version info"
print
"[-c|--check-period] sec - period for check processes. Default:
%
s"
%
check_alive_period
...
...
@@ -405,9 +423,10 @@ if __name__ == "__main__":
run_list
=
run_list
+
read_from_dir
(
from_dir
)
run_list
=
run_list
+
read_from_commandline
([
'-r'
,
'--run'
])
run_after_list
=
read_from_commandline
([
'-a'
,
'--run-after'
])
if
len
(
run_list
)
==
0
:
if
len
(
run_list
)
==
0
and
len
(
run_after_list
)
==
0
:
log_error
(
"not found run list. Use -h for help"
)
exit
(
1
)
do_monitoring
(
main_pid
,
run_list
,
not_monit
=
not_moni
t
)
do_monitoring
(
main_pid
=
main_pid
,
run_list
=
run_list
,
not_monit
=
not_monit
,
run_after_list
=
run_after_lis
t
)
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