Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
99a91ce6
Commit
99a91ce6
authored
Sep 29, 2015
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The last commit didn't really fix the bug. This one seems to do a better job :)
parent
b51b2857
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