Improve consistency of sync_compatible
when running flows in remote environments
#14660
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR ensures that functions wrapped in
@sync_compatible
execute as expected in remote environments by settingRUNNING_ASYNC_FLAG
toFalse
when running a sync function in a worker thread. Flow scripts are loaded in a worker thread without an event loop, so updating theRUNNING_ASYNC_FLAG
context variable will ensure those wrapped async functions execute as sync.I noticed that a couple of threads are created when loading a flow script. The number of created threads could be reduced by creating a sync implementation of
load_flow_from_flow_run
, but we'd likely still need to call storage block methods and pull steps in a separate thread since they are async by default.Closes #14625
Example
Checklist
maintenance
,fix
,feature
,enhancement
,docs
.<link to issue>
"mint.json
.