Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
99a91ce6
"examples/vscode:/vscode.git/clone" did not exist on "d0ea98befade9032a2a97857dd7f366dbf240621"
Commit
99a91ce6
authored
Sep 28, 2015
by
Davis King
Browse files
The last commit didn't really fix the bug. This one seems to do a better job :)
parent
b51b2857
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
8 deletions
+56
-8
setup.py
setup.py
+56
-8
No files found.
setup.py
View file @
99a91ce6
...
...
@@ -256,7 +256,6 @@ _ON_POSIX = 'posix' in sys.builtin_module_names
def
enqueue_output
(
out
,
queue
):
for
line
in
iter
(
out
.
readline
,
b
''
):
queue
.
put
(
line
)
out
.
close
()
def
_log_buf
(
buf
):
...
...
@@ -269,21 +268,70 @@ def _log_buf(buf):
log
.
info
(
line
)
def
run_process
(
cmds
):
"""run a process
def
run_process
(
cmds
,
timeout
=
None
):
"""run a process
asynchronously
:param cmds: list of commands to invoke on a shell e.g. ['make', 'install']
:param timeout: timeout in seconds (optional)
"""
#
Run the process
#
open process as its own session, and with no stdout buffering
p
=
Popen
(
cmds
,
stdout
=
PIPE
,
stderr
=
STDOUT
,
bufsize
=
1
,
close_fds
=
_ON_POSIX
,
preexec_fn
=
os
.
setsid
if
_ON_POSIX
else
None
)
# And send it's output to the console.
for
line
in
p
.
stdout
:
_log_buf
(
line
)
p
.
wait
()
q
=
Queue
()
t
=
Thread
(
target
=
enqueue_output
,
args
=
(
p
.
stdout
,
q
))
t
.
daemon
=
True
# thread dies with the program
t
.
start
()
_time
=
time
.
time
()
e
=
None
try
:
while
t
.
isAlive
():
try
:
buf
=
q
.
get
(
timeout
=
.
1
)
except
Empty
:
buf
=
b
''
_log_buf
(
buf
)
elapsed
=
time
.
time
()
-
_time
if
timeout
and
elapsed
>
timeout
:
break
# Make sure we print all the output from the process.
if
p
.
stdout
:
for
line
in
p
.
stdout
:
_log_buf
(
line
)
p
.
wait
()
except
(
KeyboardInterrupt
,
SystemExit
)
as
e
:
# if user interrupted
pass
# noinspection PyBroadException
try
:
os
.
kill
(
p
.
pid
,
signal
.
SIGINT
)
except
(
KeyboardInterrupt
,
SystemExit
)
as
e
:
pass
except
:
pass
# noinspection PyBroadException
try
:
if
e
:
os
.
kill
(
p
.
pid
,
signal
.
SIGKILL
)
else
:
p
.
wait
()
except
(
KeyboardInterrupt
,
SystemExit
)
as
e
:
# noinspection PyBroadException
try
:
os
.
kill
(
p
.
pid
,
signal
.
SIGKILL
)
except
:
pass
except
:
pass
t
.
join
(
timeout
=
0.1
)
if
e
:
raise
e
return
p
.
returncode
...
...
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