Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
ops_sdk
Project
Project
Details
Activity
Releases
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PublicSource
ops_sdk
Commits
705dcbff
Commit
705dcbff
authored
Aug 20, 2019
by
shenshuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
执行任务类
parent
bc2b5b35
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
tools.py
websdk/tools.py
+33
-0
No files found.
websdk/tools.py
View file @
705dcbff
...
...
@@ -8,6 +8,7 @@ role : 工具类
import
sys
import
re
import
time
import
subprocess
from
concurrent.futures
import
ThreadPoolExecutor
...
...
@@ -92,3 +93,35 @@ def exec_shell(cmd):
return
ret
,
stdout
.
decode
(
'utf-8'
)
.
split
(
'
\n
'
)
else
:
return
ret
,
stdout
.
decode
(
'utf-8'
)
.
replace
(
'
\n
'
,
''
)
class
RunningProcess
:
def
__init__
(
self
,
process
):
self
.
process
=
process
self
.
start_time
=
time
.
time
()
def
is_running
(
self
):
return
bool
(
self
.
process
.
poll
()
is
None
)
def
read_line
(
self
):
return
self
.
process
.
stdout
.
readline
()
@
property
def
unread_lines
(
self
):
lines
=
self
.
process
.
stdout
.
readlines
()
self
.
process
.
stdout
.
close
()
return
lines
@
property
def
run_state
(
self
):
return
bool
(
self
.
process
.
poll
()
is
0
)
def
is_timeout
(
self
,
exec_time
=
600
):
duration
=
time
.
time
()
-
self
.
start_time
if
duration
>
exec_time
:
self
.
process
.
terminate
()
self
.
process
.
wait
()
self
.
process
.
communicate
()
# print("execute timeout, execute time {}, it's killed.".format(duration))
return
True
return
False
\ No newline at end of file
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