-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dogshell.wrap's buffer_outs option effected by I/O redirection #202
Comments
After doing a little research and testing locally, I think I may have figured out why the event fails to send with multiple IO redirection. Take the example command: # datadogpy/dogshell/wrap.py
...
try:
proc = subprocess.Popen(u' '.join(cmd), stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
except Exception:
print >> sys.stderr, u"Failed to execute %s" % (repr(cmd))
raise
try:
# Let's that the threads collecting the output from the command in the
# background
out_reader = OutputReader(proc.stdout, sys.stdout if not buffer_outs else None)
err_reader = OutputReader(proc.stderr, sys.stderr if not buffer_outs else None)
out_reader.start()
err_reader.start()
# Let's quietly wait from the program's completion here et get the exit
# code when it finishes
returncode = poll_proc(proc, proc_poll_interval, cmd_timeout)
# Let's harvest the outputs collected by our background threads after
# making sure they're done reading it.
out_reader.join()
err_reader.join()
stdout = out_reader.content
stderr = err_reader.content So when To test, I commented out the following lines, and immediately the events began to transmit successfully: out_reader = OutputReader(proc.stdout, sys.stdout if not buffer_outs else None)
err_reader = OutputReader(proc.stderr, sys.stderr if not buffer_outs else None)
out_reader.start()
#err_reader.start() # Removed for testing
# Let's quietly wait from the program's completion here et get the exit
# code when it finishes
returncode = poll_proc(proc, proc_poll_interval, cmd_timeout)
# Let's harvest the outputs collected by our background threads after
# making sure they're done reading it.
out_reader.join()
#err_reader.join() # Removed for testing
stdout = out_reader.content
#stderr = err_reader.content # Removed for testing There may be a lower, more accurate fix for this, but without personal knowledge and spending more time digging into where exactly the internal logic faults on duplicate actions, the simplest solution seems to split |
[INVALID] See #201
When using
dogwrap
console script to send event to datadog servers, including the-b
(buffer_outs) option, and using I/O redirection (at least in one case) causes unsuccessful even transmission.Writing to both
stdout
,stderr
The following results in successful event transmission, and prints result to console.
Adding in null route
>/dev/null
, results in NO event transmission:Finally, keeping null route and removing
-b
(buffer_outs), results in successful event transmission without output to console:Writing only to
stdout
The following results in successful event transmission, and prints result to console:
Adding in null route
>/dev/null
, results in successful event transmission:Finally, keeping null route and removing
-b
(buffer_outs), results in successful event transmission without output to console:Commenting out the
fwrite(STDERR, 'Testing stderr');
results in all three of the original test cases working normally.Additionally, if either one of the two redirects is removed, the result is success. I.e. both work:
This suggests there is an issue with multiple IO redirection, where the final redirection (or last) redirection is
/dev/null
. Specifically, redirecting to a file instead of/dev/null
is successful in all cases above.According to
dogwrap --help
:In
datadogpy.dogshell.wrap
there is some reference tosys.stderr
,sys.stdout
:Maybe some separation of
proc.stdout/stderr
vssys.stdout/stderr
is needed?Or maybe try checking if IO redirection is present via
sys.stdout.isatty()
?Example, shows IO redirection is checked:
Then testing, we have:
May be of use:
http://stackoverflow.com/questions/21953835/run-subprocess-and-print-output-to-logging
I'm not familiar enough with python yet to understand fully how it interacts with IO redirection, but I will test to try and find a solution.
The text was updated successfully, but these errors were encountered: