How to create instances of scenes or nodes in a thread?

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

Hi,
how can I create instances of Scenes or for example the TestCube when using a function that is run by another thread?
When I try to create an instance from a threaded function, the thread never finishes and stays active forever.

Here is a quick example (commenting out the line var testcube = TestCube.new() makes the script run without problems)

extends Node

var thread1 = Thread.new()
var thread2 = Thread.new() 

 func _ready():
    print("starting thread")
    thread1.start(self, "threadedFunction1")
    thread2.start(self, "threadedFunction2")
    print("waiting to finish")
    thread1.wait_to_finish()
    thread2.wait_to_finish()
    print("finished")

func threadedFunction1(var data):
    print("load testcube")
    var testcube = TestCube.new()
    call_deferred("done1")

func threadedFunction2(var data):
    print("doing something else")
    call_deferred("done2")

func done1():
    print("thread1 done")

func done2():
    print("thread2 done")

Thanks.