Repository: godot
Issue: Multithreaded import causes core dumps
Labels: bug,topic:editor,needs testing,topic:import,crash

### Godot version

v4.2.beta.custom_build [fd33c7b32]

### System information

Linux

### Issue description

I'm working on a tool based on Godot Editor. I have a bunch of import scripts, which are responsible for doing conversion from foreign (and custom) data formats, into Godot-compatible formats (scenes, meshes, materials). During development I was importing single files. I was I also importing multiple files, but through GDScript. Today I dropped a whole folder with many files, and Godot started crashing. I've tested 4.1 stable, and I've compiled custom master (4.2 beta).

I spent half a day to figure out where is the problem, and I found that it wasn't related to my parsers nor source data files, but to enabled multithreading for Import. When I disabled multithreading, the whole process finished successfully.

![image](https://github.com/godotengine/godot/assets/133269979/ca130e3f-9d77-46cc-a2b1-6adb490b55fc)


### Steps to reproduce

Reproducing the issue with MRP can be hard for me, because I'm not sure what is the root cause. My importer is implemented in GDScript. There are bunch of custom classes, which are related to each other.

During the import, which was run within the Godot Editor (i.e. by dragging and dropping the files), I found an error which wasn't present when I was parsing these same files via GDScript (at runtime). Here is the excerpt from the code and errors:

```gdscript
extends Node
class_name SomeClass

static var _used_names = {}

func get_unique_name(name):
    if _used_names.has(name):
        _used_names[name] += 1
    else:
        _used_names[name] = 0
    return "name_%s" % _used_names[name]
```

which was called from instance like that:

```gdscript
var x = SomeClass.new()
x.name = x.get_unique_name("some")
```

Here are the errors:
```
  res://addons/maszyna/importers/node.gd:69 - Invalid call. Nonexistent function 'has' in base 'Nil'.
  res://addons/maszyna/importers/node.gd:48 - Invalid set index 'name' (on base: 'Node3D (MaSzyna_Model)') with value of type 'Nil'.
```

So first Godot said that `_used_names` declared with a dictionary `{}` has `Nil` value. Then, because `Nil.has()` failed, it was trying to set `Nil` as a `x.name` .

I feel that there is something wrong with handling static variables in GDScript.

I'm also using static vars in two cases:
1. for an implementation of singletons:
```gdscript
static var _instance
static func singleton():
    if not _instance:
         _instance = new()
    return _instance
```
2. for instantiating importers and exporters, like this:
```gdscript
extends Node
class_name CustomNode

static var importer = load("res://path/to/custom_node_importer.gd").new()
static var exporter = load("res://path/to/custom_node_exporter.gd").new()
```

which I'm calling like this:
```gdscript

# export

var x = get_node("custom")  # <--- CustomNode
x.exporter.export(...)

# and import

var x = CustomNode.importer.import(...)  # importer returns instance of CustomNode
```

----

Because the error about undeclared static var is absent when multithreaded import is disabled, I think that the issue may be related to handling static vars/funcs in GDScript and threads.

### Minimal reproduction project

I can't create MRP for now.