File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 1+ import io
12import sys
23from inspect import iscoroutinefunction
34from threading import Lock
@@ -64,6 +65,15 @@ def from_args(cls) -> Self:
6465 return cls (address , log_level = log_level )
6566
6667 def __init__ (self , address : str , * , log_level : int = logging .INFO ) -> None :
68+ # When a module is launched by viam-server, its stdout is not connected to a tty. In
69+ # response, python disables line buffering, which prevents `print` statements from being
70+ # immediately flushed to viam-server. This behavior can be confusing, interfere with
71+ # debugging, and is non-standard when compared to other languages. Here, stdout and stderr
72+ # are reconfigured to immediately flush.
73+ if isinstance (sys .stdout , io .TextIOWrapper ):
74+ sys .stdout .reconfigure (line_buffering = True )
75+ if isinstance (sys .stderr , io .TextIOWrapper ):
76+ sys .stderr .reconfigure (line_buffering = True )
6777 self ._address = address
6878 self .server = Server (resources = [], module_service = ModuleRPCService (self ))
6979 self ._log_level = log_level
You can’t perform that action at this time.
0 commit comments