Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
20eda08d
Commit
20eda08d
authored
5 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
bugfix for call_and_return_stdout
parent
98468984
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
satella/processes.py
+9
-2
9 additions, 2 deletions
satella/processes.py
with
9 additions
and
2 deletions
satella/processes.py
+
9
−
2
View file @
20eda08d
...
...
@@ -19,15 +19,20 @@ def read_nowait(process: subprocess.Popen, output_list: tp.List[str]):
def
call_and_return_stdout
(
args
:
tp
.
Union
[
str
,
tp
.
List
[
str
]],
timeout
:
tp
.
Optional
[
int
]
=
None
,
encoding
:
tp
.
Optional
[
str
]
=
None
,
expected_return_code
:
int
=
0
,
**
kwargs
)
->
tp
.
Union
[
bytes
,
str
]:
"""
Call a process and return it
'
s stdout.
Everything in kwargs will be passed to subprocess.Popen
A bytes object will be returned if encoding is not defined, else stdout will be decoded
according to specified encoding
:param args: arguments to run the program with. If passed a string, it will be split on space.
:param timeout: amount of seconds to wait for the process result. If process does not complete
within this time, it will be sent a SIGKILL
:param encoding: encoding with which to decode stdout. If none is passed, it will be returned as a bytes object
:param expected_return_code: an expected return code of this process. 0 is the default. If process
returns anything else, ProcessFailed will be raise
:raises ProcessFailed: process
'
result code was different from the requested
...
...
@@ -47,13 +52,15 @@ def call_and_return_stdout(args: tp.Union[str, tp.List[str]],
except
subprocess
.
TimeoutExpired
:
proc
.
kill
()
proc
.
wait
()
reader_thread
.
join
()
if
proc
.
returncode
!=
expected_return_code
:
raise
ProcessFailed
(
proc
.
returncode
)
else
:
if
kwargs
.
get
(
'
encoding
'
,
None
)
is
None
:
if
encoding
is
None
:
return
b
''
.
join
(
stdout_list
)
else
:
return
''
.
join
(
stdout_list
)
return
''
.
join
((
row
.
decode
(
encoding
)
for
row
in
stdout_list
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment