Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Only print to stdout if stdout is connected to a tty(-like) device #941

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions raven/transport/threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import logging
import threading
import os
import sys

from time import sleep, time

Expand Down Expand Up @@ -64,18 +65,20 @@ def main_thread_terminated(self):

if not self._timed_queue_join(initial_timeout):
# if that didn't work, wait a bit longer
# NB that size is an approximation, because other threads may
# add or remove items
size = self._queue.qsize()

print("Sentry is attempting to send %i pending error messages"
% size)
print("Waiting up to %s seconds" % timeout)

if os.name == 'nt':
print("Press Ctrl-Break to quit")
else:
print("Press Ctrl-C to quit")

if sys.stdout.isatty():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should test against stdin, not stdout.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... as we are printing to stdout, I'd propose to - if you want to test for stdin - to test for both. At least, I also don't want to see those messages when redirecting a console application to a file, maybe by nohup or something.

import sys
sys.stdout.isatty()
True

on my machine.

# NB that size is an approximation, because other threads
# may add or remove items
size = self._queue.qsize()

print("Sentry is attempting to send %i "
"pending error messages" % size)
print("Waiting up to %s seconds" % timeout)

if os.name == 'nt':
print("Press Ctrl-Break to quit")
else:
print("Press Ctrl-C to quit")

self._timed_queue_join(timeout - initial_timeout)

Expand Down