Is it possible to manually flush print()?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By azurvii
:warning: Old Version Published before Godot 3 was released.

So for quite a few occasions I was unable to grab the output since the print happened before the program ends, since I guess the output buffer was not flushed when exiting.

The print output does not appear in the output tab in the editor?

tiernich | 2016-05-13 17:01

Normally it does, but a few print()s right before quitting the program does not.

azurvii | 2016-05-13 22:06

So weird… can i see the code?

tiernich | 2016-05-13 22:12

This could demonstrate:

extends Control

func _ready():
	print("Can you see me?")
	get_tree().quit()

azurvii | 2016-05-13 22:41

ok, i can confirme same behavior here, a workaround is:

func _ready():
    print("Can you see me?")
    get_node("Timer").start()

func _on_Timer_timeout():
    get_tree().quit()

the time delay is 0.1, is this a viable option for you?

tiernich | 2016-05-14 04:14

Thanks for the tip. That feels like the print function is called in the future event loop, which may have been terminated by get_tree().quit() before running. I’ll file a bug to discuss this with the team.

azurvii | 2016-05-14 08:55