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
Crossbar prints empty lines to the terminal #2050
Comments
yes, crossbar tests if it can use direct raw terminal output with no redirection by writing to the terminal device Line 55 in 8a261c5
|
@oberstet Would you consider using an invisible character to test the terminal device? For example |
Or a simple check if it's writable? import os
os.access('/dev/tty', os.W_OK) |
because that's just a flag, not the same as actually writing to the device, which is the real deal we want to test for here. |
The issue with the current implementation is that it prints new lines even if not using +++ b/crossbar/_util.py
@@ -14,6 +14,7 @@ import re
import inspect
import uuid
import copy
+import functools
from collections.abc import Mapping
import click
@@ -39,28 +40,32 @@ def set_flags_from_args(_args):
DEBUG_PROGRAMFLOW = True
-# FS path to controlling terminal
-_TERMINAL = None
+@functools.lru_cache(1)
+def _terminal():
+ # FS path to controlling terminal
+ _TERMINAL = None
-# Linux, *BSD and MacOSX
-if sys.platform.startswith('linux') or 'bsd' in sys.platform or sys.platform.startswith('darwin'):
- _TERMINAL = '/dev/tty' if os.path.exists('/dev/tty') else None
-# Windows
-elif sys.platform in ['win32']:
- pass
-# Other OS
-else:
- pass
+ # Linux, *BSD and MacOSX
+ if sys.platform.startswith('linux') or 'bsd' in sys.platform or sys.platform.startswith('darwin'):
+ _TERMINAL = '/dev/tty' if os.path.exists('/dev/tty') else None
+ # Windows
+ elif sys.platform in ['win32']:
+ pass
+ # Other OS
+ else:
+ pass
+
+ # still, we might not be able to use TTY, so duck test it:
+ if _TERMINAL:
+ try:
+ with open('/dev/tty', 'w') as f:
+ f.write('\n')
+ f.flush()
+ except:
+ # under systemd: OSError: [Errno 6] No such device or address: '/dev/tty'
+ _TERMINAL = None
-# still, we might not be able to use TTY, so duck test it:
-if _TERMINAL:
- try:
- with open('/dev/tty', 'w') as f:
- f.write('\n')
- f.flush()
- except:
- # under systemd: OSError: [Errno 6] No such device or address: '/dev/tty'
- _TERMINAL = None
+ return _TERMINAL
def class_name(obj):
@@ -165,7 +170,7 @@ def term_print(text):
if DEBUG_LIFECYCLE:
text = '{:<44}'.format(text)
text = click.style(text, fg='blue', bold=True)
- if _TERMINAL:
+ if _terminal():
with open('/dev/tty', 'w') as f:
f.write(text + '\n')
f.flush() |
ok, right, if |
During initialization
crossbar
prints empty lines to the terminal. Output redirection cannot mute it sincecrossbar
writes directly to/dev/tty
. This is especially annoying when runningcrossbar
as a subprocess when no extra output is expected.crossbar/crossbar/_util.py
Lines 58 to 60 in 8a261c5
The text was updated successfully, but these errors were encountered: