Thread not running

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

I have created a thread to execute a method, but this thread is not generating any output.

extends Node

var thread = null

func _ready():
	thread = Thread.new()
	var err = thread.start(self, "work")

func work():
	print("oi")
	while(true):
		print("oi")

I need to create a thread to be communicating with a TCP socket, however it is not working :frowning:

:bust_in_silhouette: Reply From: Marlon Henry Schweig

It worked when I put an argument to the method.

extends Node

var thread = null



func _ready():
	thread = Thread.new()
	var err = thread.start(self, "work")

func work(userdata):
    print("oi")
    while(true):
        print("oi")

Maybe a bug?

The documentation says:

Error start ( Object instance, String method, Variant userdata=NULL, int priority=1 )
Start a new Thread, it will run “method” on object “instance” using “userdata” as an argument and running with “priority”, one of PRIORITY_* enum.

The default value for “userdata” may be NULL, but it’s still there and will be passed, so if your work-method doesn’t have a parameter to receive it the signature will not match.

Warlaan | 2017-07-27 20:45

Yes… but i can’t call a func without args?

Marlon Henry Schweig | 2017-07-28 00:53