+1 vote
OS.execute(str(userdir) + "/youtube-dl",  ["--dump-single-json", "ytsearc7:%s"%[term]], true, output)

The code prints output only if blocking is set to true, else it prints empty list[]. However if the execute is set to blocking it doesn't result anything.

I want to have something like a signal that runs after the non-blocking OS.execute

asked May 14 in Engine by Bugdot (43 points)
edited May 14 by Bugdot

Of course, this way of calling a subprocess won't give you a result immediately if you don't block. Not blocking means it's fire-and-forget then...

That sounds like a feature request, which should be asked on Github.

An alternative would be to do this in a thread.

1 Answer

+1 vote
Best answer

The only method to get output while having it as non-blocking is to use threads.

This is the code I'm using to do that.

I set OS.exectute to blocking and then call it in a thread.

However I have a new problem. I need to kill the thread when needed.


func print_search(term):
    search_ongoing = true
    search_completed = false
    print("Search starting for "+ term)
    OS.execute(str(userdir) + "/youtube-dl",  ["--dump-single-json", "ytsearch1:"+term], true, output)
    search_ongoing = false
    search_completed = true
    search_read = false
    print("Search finished")
    $StatusLabel.text="Search finished"

func _on_Search_pressed():
    if search_ongoing == false:
        search_thread = Thread.new()
        var search_err = search_thread.start(self, "print_search", [$UISearch/LineEdit.text])
answered May 16 by Bugdot (43 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.