Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Boxiang Sun
slapos.core
Commits
7d50f1f7
Commit
7d50f1f7
authored
Jan 25, 2023
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Plain Diff
SlapPopen: Fix select-based timeout reads
See merge request
nexedi/slapos.core!477
parents
581b8aa6
65995034
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
36 deletions
+35
-36
setup.py
setup.py
+1
-0
slapos/grid/utils.py
slapos/grid/utils.py
+34
-36
No files found.
setup.py
View file @
7d50f1f7
...
...
@@ -80,6 +80,7 @@ setup(name=name,
'distro'
,
'subprocess32; python_version<"3"'
,
'enum34; python_version<"3"'
,
'selectors34; python_version<"3"'
,
# used by SlapPopen (grid/utils)
'ipaddress; python_version<"3"'
,
# used by whitelistfirewall
]
+
additional_install_requires
,
extras_require
=
extras_require
,
...
...
slapos/grid/utils.py
View file @
7d50f1f7
...
...
@@ -33,7 +33,6 @@ import hashlib
import
os
import
pkg_resources
import
pwd
import
select
import
stat
import
sys
import
logging
...
...
@@ -41,8 +40,10 @@ import psutil
import
time
if
sys
.
version_info
>=
(
3
,):
import
selectors
import
subprocess
else
:
import
selectors34
as
selectors
import
subprocess32
as
subprocess
...
...
@@ -155,49 +156,46 @@ class SlapPopen(subprocess.Popen):
self
.
stdin
.
close
()
self
.
stdin
=
None
stderr_fileno
=
stdout_fileno
=
None
buffers
=
{}
if
kwargs
[
'stdout'
]
is
subprocess
.
PIPE
:
line_logger
=
LineLogger
(
logger
)
stdout_fileno
=
self
.
stdout
.
fileno
()
buffers
[
stdout_fileno
]
=
[]
buffers
[
self
.
stdout
]
=
[]
if
kwargs
[
'stderr'
]
is
subprocess
.
PIPE
:
stderr_fileno
=
self
.
stderr
.
fileno
()
buffers
[
stderr_fileno
]
=
[]
poll
=
select
.
poll
()
for
fd
in
buffers
:
poll
.
register
(
fd
)
active
=
len
(
buffers
)
if
timeout
is
not
None
:
deadline
=
time
.
time
()
+
timeout
while
active
:
for
fd
,
_
in
poll
.
poll
(
timeout
):
data
=
os
.
read
(
fd
,
4096
).
decode
(
'utf-8'
,
'replace'
)
if
data
:
if
fd
==
stdout_fileno
:
line_logger
.
update
(
data
)
buffers
[
fd
].
append
(
data
)
else
:
if
fd
==
stdout_fileno
:
line_logger
.
flush
()
poll
.
unregister
(
fd
)
active
-=
1
if
timeout
is
not
None
:
timeout
=
deadline
-
time
.
time
()
if
timeout
<=
0
:
timeout
=
0
break
buffers
[
self
.
stderr
]
=
[]
try
:
self
.
wait
(
timeout
=
timeout
)
with
selectors
.
DefaultSelector
()
as
selector
:
for
fileobj
in
buffers
:
selector
.
register
(
fileobj
,
selectors
.
EVENT_READ
)
if
timeout
is
not
None
:
deadline
=
time
.
time
()
+
timeout
while
selector
.
get_map
():
for
key
,
_
in
selector
.
select
(
timeout
):
data
=
os
.
read
(
key
.
fd
,
4096
).
decode
(
'utf-8'
,
'replace'
)
if
data
:
if
key
.
fileobj
==
self
.
stdout
:
line_logger
.
update
(
data
)
buffers
[
key
.
fileobj
].
append
(
data
)
else
:
if
key
.
fileobj
==
self
.
stdout
:
line_logger
.
flush
()
selector
.
unregister
(
key
.
fileobj
)
key
.
fileobj
.
close
()
if
timeout
is
not
None
:
timeout
=
deadline
-
time
.
time
()
if
timeout
<=
0
:
timeout
=
0
break
self
.
wait
(
timeout
=
timeout
)
except
subprocess
.
TimeoutExpired
as
e
:
for
p
in
killProcessTree
(
self
.
pid
,
logger
):
p
.
wait
(
timeout
=
10
)
# arbitrary timeout, wait until process is killed
self
.
poll
()
# set returncode (and avoid still-running warning)
e
.
output
=
e
.
stdout
=
''
.
join
(
buffers
.
get
(
s
tdout_fileno
,
()))
e
.
stderr
=
''
.
join
(
buffers
.
get
(
s
tderr_fileno
,
()))
e
.
output
=
e
.
stdout
=
''
.
join
(
buffers
.
get
(
s
elf
.
stdout
,
()))
e
.
stderr
=
''
.
join
(
buffers
.
get
(
s
elf
.
stderr
,
()))
raise
finally
:
for
s
in
(
self
.
stdout
,
self
.
stderr
):
...
...
@@ -207,8 +205,8 @@ class SlapPopen(subprocess.Popen):
except
OSError
:
pass
self
.
output
=
''
.
join
(
buffers
.
get
(
s
tdout_fileno
,
()))
self
.
error
=
''
.
join
(
buffers
.
get
(
s
tderr_fileno
,
()))
self
.
output
=
''
.
join
(
buffers
.
get
(
s
elf
.
stdout
,
()))
self
.
error
=
''
.
join
(
buffers
.
get
(
s
elf
.
stderr
,
()))
def
md5digest
(
url
):
...
...
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