tucono A couple of thoughts.
First of all I don't think this is sustainable or even advisable. What if your scenes at some point in development or game state are so busy that there will never be enough time budget to run your expensive code?
And how do you know how long it will take to run?
Also keep in mind that _physics_process() is not like _process() and is not guaranteed to be called every single frame. It is totally possible that _physics_process() will be called 2 or 3 times in a row in a single normal frame and then not again for the next 2 frames.
Can you make this expensive code reentrant and then only do a little bit of work every physics frame instead of all at once? Then you could just slowly nibble away at it every frame.
If not then maybe you should just try running it for example every 30th or 60th physics frame (so roughly once a second) and if that physics frame takes a longer time then see if that is even noticable.
But if you really want to keep your initial idea: You can change the process_physics_priority so that you could have one node that acts as a kind of watchdog and has the highest priority and is guaranteed to get called first. That node could take the current time, knowing that this is when physics processing started. And then put your expensive code into a node that has the lowest priority so it will get called last. Then you could check how much time has passed and decide what to do.
But I have no idea if this priority is taken into account for the whole scene tree or if it only respected among the nodes of one scene.
https://docs.godotengine.org/en/latest/classes/class_node.html#class-node-property-process-physics-priority