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
1
2
import sys
2
3
from inspect import iscoroutinefunction
3
4
from threading import Lock
@@ -64,6 +65,15 @@ def from_args(cls) -> Self:
64
65
return cls (address , log_level = log_level )
65
66
66
67
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 )
67
77
self ._address = address
68
78
self .server = Server (resources = [], module_service = ModuleRPCService (self ))
69
79
self ._log_level = log_level
You can’t perform that action at this time.
0 commit comments