Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindinsight
提交
1f2f8584
M
mindinsight
项目概览
MindSpore
/
mindinsight
通知
7
Star
3
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindinsight
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1f2f8584
编写于
4月 20, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
4月 20, 2020
浏览文件
操作
浏览文件
下载
差异文件
!44 start/stop command should return correct exit-code based on result of process
Merge pull request !44 from liangyongxiong/master
上级
c568a9bb
1bc356ad
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
41 addition
and
26 deletion
+41
-26
mindinsight/backend/run.py
mindinsight/backend/run.py
+5
-3
mindinsight/scripts/start.py
mindinsight/scripts/start.py
+6
-5
mindinsight/scripts/stop.py
mindinsight/scripts/stop.py
+8
-7
mindinsight/utils/command.py
mindinsight/utils/command.py
+19
-8
mindinsight/utils/log.py
mindinsight/utils/log.py
+3
-3
未找到文件。
mindinsight/backend/run.py
浏览文件 @
1f2f8584
...
...
@@ -231,6 +231,8 @@ def start():
log_size
=
_get_file_size
(
errorlog_abspath
)
stdout
=
setup_logger
(
'mindinsight'
,
'stdout'
,
console
=
True
,
logfile
=
False
,
formatter
=
'%(message)s'
)
# start server
process
=
subprocess
.
Popen
(
shlex
.
split
(
cmd
),
...
...
@@ -241,15 +243,15 @@ def start():
)
_
,
stderr
=
process
.
communicate
()
if
stderr
:
print
(
stderr
.
decode
())
stdout
.
error
(
stderr
.
decode
())
# wait command success to end when gunicorn running in daemon.
if
gunicorn_conf
.
daemon
and
process
.
wait
()
==
0
:
state_result
=
_check_server_start_stat
(
errorlog_abspath
,
log_size
)
# print gunicorn start state to stdout
print
(
'Web address: http://{}:{}'
.
format
(
settings
.
HOST
,
settings
.
PORT
))
stdout
.
info
(
'Web address: http://{}:{}'
.
format
(
settings
.
HOST
,
settings
.
PORT
))
for
line
in
state_result
[
"prompt_message"
]:
print
(
line
)
stdout
.
info
(
line
)
if
__name__
==
'__main__'
:
...
...
mindinsight/scripts/start.py
浏览文件 @
1f2f8584
...
...
@@ -15,6 +15,7 @@
"""Start mindinsight service."""
import
os
import
sys
import
argparse
from
importlib
import
import_module
...
...
@@ -183,19 +184,19 @@ class Command(BaseCommand):
"""
for
key
,
value
in
args
.
__dict__
.
items
():
if
value
is
not
None
:
self
.
log
ger
.
info
(
'%s = %s'
,
key
,
value
)
self
.
log
file
.
info
(
'%s = %s'
,
key
,
value
)
try
:
self
.
check_port
()
except
PortNotAvailableError
as
error
:
print
(
error
.
message
)
self
.
log
ger
.
error
(
error
.
message
)
return
self
.
console
.
error
(
error
.
message
)
self
.
log
file
.
error
(
error
.
message
)
sys
.
exit
(
1
)
run_module
=
import_module
(
'mindinsight.backend.run'
)
run_module
.
start
()
self
.
log
ger
.
info
(
'Start mindinsight done.'
)
self
.
log
file
.
info
(
'Start mindinsight done.'
)
def
check_port
(
self
):
"""Check port."""
...
...
mindinsight/scripts/stop.py
浏览文件 @
1f2f8584
...
...
@@ -15,6 +15,7 @@
"""Stop mindinsight service."""
import
os
import
sys
import
argparse
import
signal
import
getpass
...
...
@@ -96,10 +97,10 @@ class Command(BaseCommand):
port
,
pid
=
args
.
port
,
args
.
pid
if
not
pid
:
msg
=
f
'No mindinsight service found for port
{
port
}
'
print
(
msg
)
return
self
.
console
.
error
(
msg
)
sys
.
exit
(
1
)
self
.
log
ger
.
info
(
'Stop mindinsight with port %s and pid %s.'
,
port
,
pid
)
self
.
log
file
.
info
(
'Stop mindinsight with port %s and pid %s.'
,
port
,
pid
)
process
=
psutil
.
Process
(
pid
)
child_pids
=
[
child
.
pid
for
child
in
process
.
children
()]
...
...
@@ -108,8 +109,8 @@ class Command(BaseCommand):
try
:
os
.
kill
(
pid
,
signal
.
SIGKILL
)
except
PermissionError
:
print
(
'kill pid %s failed due to permission error'
%
pid
)
return
self
.
console
.
info
(
'kill pid %s failed due to permission error'
%
pid
)
sys
.
exit
(
1
)
# cleanup gunicorn worker processes
for
child_pid
in
child_pids
:
...
...
@@ -119,9 +120,9 @@ class Command(BaseCommand):
pass
for
hook
in
HookUtils
.
instance
().
hooks
():
hook
.
on_shutdown
(
self
.
log
ger
)
hook
.
on_shutdown
(
self
.
log
file
)
print
(
'Stop mindinsight service successfully'
)
self
.
console
.
info
(
'Stop mindinsight service successfully'
)
def
get_process
(
self
,
port
):
"""
...
...
mindinsight/utils/command.py
浏览文件 @
1f2f8584
...
...
@@ -30,7 +30,11 @@ class BaseCommand:
name
=
''
description
=
''
logger
=
None
# logger for console output instead of built-in print
console
=
None
# logger for log file recording in case audit is required
logfile
=
None
def
add_arguments
(
self
,
parser
):
"""
...
...
@@ -64,21 +68,28 @@ class BaseCommand:
Args:
args (Namespace): parsed arguments to hold customized parameters.
"""
error
=
None
try
:
self
.
update_settings
(
args
)
except
MindInsightException
as
error
:
print
(
error
.
message
)
else
:
self
.
logger
=
setup_logger
(
'scripts'
,
self
.
name
)
self
.
run
(
args
)
except
MindInsightException
as
e
:
error
=
e
self
.
console
=
setup_logger
(
'mindinsight'
,
'console'
,
console
=
True
,
logfile
=
False
,
formatter
=
'%(message)s'
)
if
error
is
not
None
:
self
.
console
.
error
(
error
.
message
)
sys
.
exit
(
1
)
self
.
logfile
=
setup_logger
(
'scripts'
,
self
.
name
,
console
=
False
,
logfile
=
True
)
self
.
run
(
args
)
def
main
():
"""Entry point for mindinsight CLI."""
console
=
setup_logger
(
'mindinsight'
,
'console'
,
console
=
True
,
logfile
=
False
,
formatter
=
'%(message)s'
)
if
(
sys
.
version_info
.
major
,
sys
.
version_info
.
minor
)
<
(
3
,
7
):
print
(
'Python version should be at least 3.7'
)
return
console
.
error
(
'Python version should be at least 3.7'
)
sys
.
exit
(
1
)
permissions
=
os
.
R_OK
|
os
.
W_OK
|
os
.
X_OK
...
...
mindinsight/utils/log.py
浏览文件 @
1f2f8584
...
...
@@ -146,7 +146,7 @@ def get_logger(sub_module, log_name):
return
logging
.
getLogger
(
name
=
'{}.{}'
.
format
(
sub_module
,
log_name
))
def
setup_logger
(
sub_module
,
log_name
,
console
=
False
,
logfile
=
True
,
**
kwargs
):
def
setup_logger
(
sub_module
,
log_name
,
**
kwargs
):
"""
Setup logger with sub module name and log file name.
...
...
@@ -189,12 +189,12 @@ def setup_logger(sub_module, log_name, console=False, logfile=True, **kwargs):
if
not
formatter
:
formatter
=
settings
.
LOG_FORMAT
if
console
:
if
kwargs
.
get
(
'console'
,
True
)
:
console_handler
=
logging
.
StreamHandler
(
sys
.
stdout
)
console_handler
.
formatter
=
MindInsightFormatter
(
sub_module
,
formatter
)
logger
.
addHandler
(
console_handler
)
if
logfile
:
if
kwargs
.
get
(
'logfile'
,
True
)
:
max_bytes
=
kwargs
.
get
(
'maxBytes'
,
settings
.
LOG_ROTATING_MAXBYTES
)
if
not
isinstance
(
max_bytes
,
int
)
or
not
max_bytes
>
0
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录