Sys.stdout.write from python 3 not being captured by Glitch console

Hello! I’m running a Python 3 application in Glitch, but I’m having an odd issue with output from the process not being captured by the console. (URL: https://glitch.com/edit/#!/elated-peridot-island)

I see debug text written by Flask, but span text (which is being written via a call to sys.stdout.write) only intermittently comes through. If I go into the console and run the program manually (or a small repro case) then the output will ‘appear’ both in the history and for a short time, maybe until the container is restarted? But I can’t figure out a permanent fix.

Hi Austin, is the project private? I can’t see it when I visit.

It accidentally was – I made it unprivate.

Cool thanks, what can I run to replicate this? I do have some experience with Python on Glitch but not Flask.

You should be able to run the existing sample and hit the root handler or the /fib?i= endpoint, they should both have a blob of JSON printed to the console that doesn’t happen. I was able to run the python script from the console with a different port bound and see it there.

I added a better repro case in that project in test.py – if you run it now, in the Glitch logs you’ll see “Hello world from OpenTelemetry Python!” but if you run it in the console through python3 test.py then you should see something like this –

ello world from OpenTelemetry Python!
Span(name="baz", context=SpanContext(trace_id=0x71819542fde671acee0759fb389f9b3d, span_id=0xd24959a734f4a5d8, trace_state={}), kind=SpanKind.INTERNAL, parent=Span(name="bar", context=SpanContext(trace_id=0x71819542fde671acee0759fb389f9b3d, span_id=0x2e9e0dacf6380082, trace_state={})), start_time=2020-03-02T23:10:59.262774Z, end_time=2020-03-02T23:10:59.262921Z)Span(name="bar", context=SpanContext(trace_id=0x71819542fde671acee0759fb389f9b3d, span_id=0x2e9e0dacf6380082, trace_state={}), kind=SpanKind.INTERNAL, parent=Span(name="foo", context=SpanContext(trace_id=0x71819542fde671acee0759fb389f9b3d, span_id=0xaeacaf619ebc4d26, trace_state={})), start_time=2020-03-02T23:10:59.262689Z, end_time=2020-03-02T23:10:59.263228Z)Span(name="foo", context=SpanContext(trace_id=0x71819542fde671acee0759fb389f9b3d, span_id=0xaeacaf619ebc4d26, trace_state={}), kind=SpanKind.INTERNAL, parent=None, start_time=2020-03-02T23:10:59.262534Z, end_time=2020-03-02T23:10:59.263336Z)

Thanks so much that helps a lot. I think this may be a bug, I’m going to file a story and I can also ask one of our engineers who uses opentelemetry to look at it.

1 Like

So we did some debugging and found the logs view in glitch isn’t the same as terminal output because waits for a newline to show the latest log line. You can flush the sys.stdout.write output by making sure you output a newline via either print or sys.stdout.write('\n') in your code. See https://glitch.com/edit/#!/lofty-chiseled-albacore Thanks to @potch for that. I’ve also filed a bug on this.

Fantastic! I can do that as a workaround for now. Thanks so much!

2 Likes