This relates to the “dynamic provider” that TS/JS has but Python doesn’t. One possibility is to register callbacks with the provider to run, but from what I can tell, the provider is running in a different python process than the user code.
@incalculable-sundown-82514 correct me if I’m wrong, but my understanding is that the user code runs in an async function called by the constructor of the Stack object. While it runs, each call to a pulumi resource registers an RPC with the engine. The RPCs call the provider, which awaits each of the inputs. As each of the resource’s inputs resolve, the RPC completes. When all the RPCs have completed, the run has completed.
So to hook in with the provider, we’d have to provide code that was not bound to any of the user variables, but could be bound to the RPC inputs/outputs.