Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mitogen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
mitogen
Commits
cb71ce94
Commit
cb71ce94
authored
Mar 25, 2018
by
David Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue #155: core: be more careful reconfiguring stdio
Many dragons present!
parent
443c94eb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
5 deletions
+22
-5
mitogen/core.py
mitogen/core.py
+22
-5
No files found.
mitogen/core.py
View file @
cb71ce94
...
...
@@ -1452,17 +1452,34 @@ class ExternalContext(object):
mitogen
.
parent_id
=
parent_ids
[
0
]
def
_setup_stdio
(
self
):
self
.
stdout_log
=
IoLogger
(
self
.
broker
,
'stdout'
,
1
)
self
.
stderr_log
=
IoLogger
(
self
.
broker
,
'stderr'
,
2
)
# Reopen with line buffering.
sys
.
stdout
=
os
.
fdopen
(
1
,
'w'
,
1
)
# We must open this prior to closing stdout, otherwise it will recycle
# a standard handle, the dup2() will not error, and on closing it, we
# lose a standrd handle, causing later code to again recycle a standard
# handle.
fp
=
open
(
'/dev/null'
)
# When sys.stdout was opened by the runtime, overwriting it will not
# cause close to be called. However when forking from a child that
# previously used fdopen, overwriting it /will/ cause close to be
# called. So we must explicitly close it before IoLogger overwrites the
# file descriptor, otherwise the assignment below will cause stdout to
# be closed.
sys
.
stdout
.
close
()
sys
.
stdout
=
None
try
:
os
.
dup2
(
fp
.
fileno
(),
0
)
os
.
dup2
(
fp
.
fileno
(),
1
)
os
.
dup2
(
fp
.
fileno
(),
2
)
finally
:
fp
.
close
()
self
.
stdout_log
=
IoLogger
(
self
.
broker
,
'stdout'
,
1
)
self
.
stderr_log
=
IoLogger
(
self
.
broker
,
'stderr'
,
2
)
# Reopen with line buffering.
sys
.
stdout
=
os
.
fdopen
(
1
,
'w'
,
1
)
def
_dispatch_one
(
self
,
msg
):
data
=
msg
.
unpickle
(
throw
=
False
)
_v
and
LOG
.
debug
(
'_dispatch_calls(%r)'
,
data
)
...
...
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