Skip to content

Add Cluster.called_from_running_loop and fix Cluster.asynchronous#7941

Merged
jrbourbeau merged 3 commits into
dask:mainfrom
jacobtomlinson:called_from_running_loop
Jun 26, 2023
Merged

Add Cluster.called_from_running_loop and fix Cluster.asynchronous#7941
jrbourbeau merged 3 commits into
dask:mainfrom
jacobtomlinson:called_from_running_loop

Conversation

@jacobtomlinson

Copy link
Copy Markdown
Member

Closes #7940

This PR contains two changes:

  • Update SyncMethodMixin.asynchronous to return False if not asynchronous and no loop is running.
  • Move called_from_running_loop check out of SpecCluster.__init__ and into a property on Cluster to allow for better reuse in subclasses.

xref dask/dask-kubernetes#738

  • Tests added / passed
  • Passes pre-commit run --all-files

Comment thread distributed/deploy/cluster.py Outdated
getattr(self.loop, "asyncio_loop", None) is asyncio.get_running_loop()
)
except RuntimeError:
return self.asynchronous

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be the value passed in def __init__(self, *, ..., asynchronous=False) not the computed attribute

@jacobtomlinson jacobtomlinson Jun 22, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I've updated it to store that in a private attribute to avoid folks using it instead of the property.

@jacobtomlinson jacobtomlinson requested a review from graingert June 22, 2023 11:30
@github-actions

github-actions Bot commented Jun 22, 2023

Copy link
Copy Markdown
Contributor

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

       20 files  ±0         20 suites  ±0   13h 12m 42s ⏱️ + 53m 17s
  3 698 tests ±0    3 576 ✔️  - 15     106 💤 ±0  16 +15 
35 766 runs  ±0  33 964 ✔️  - 53  1 751 💤 +3  51 +50 

For more details on these failures, see this check.

Results for commit e9601a9. ± Comparison against base commit 429ef8c.

♻️ This comment has been updated with latest results.

scheduler_sync_interval=1,
):
self._loop_runner = LoopRunner(loop=loop, asynchronous=asynchronous)
self.__asynchronous = asynchronous

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly confused. The SyncMethodMixin is checking for _asynchronous but you chose to use an attribute with name mangling (double underscore) so this attribute will never be detected by the mixin. is this intentional?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see _asynchronous is never set anywhere apart from Client and Actor. So the mixin always falls back to the default for cluster objects. I went with the double underscore because I only wanted to use it for this one purpose and didn't want to collide with whatever _asynchronous is being used for, given that it was unclear to me what _asynchronous is even doing.

Happy to do something else here, do you have a suggestion?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good. Just wanted to make sure this is intentional. For this usecase the mangling is a good choice.

@jrbourbeau

Copy link
Copy Markdown
Member

Thanks @jacobtomlinson for the fix and @fjetter @graingert for reviewing. I'll make sure this is included in the release later today

@jrbourbeau jrbourbeau changed the title Add Cluster.called_from_running_loop and fix Cluster.asynchronous Add Cluster.called_from_running_loop and fix Cluster.asynchronous Jun 26, 2023
@jrbourbeau jrbourbeau merged commit 3b0376f into dask:main Jun 26, 2023
@jacobtomlinson jacobtomlinson deleted the called_from_running_loop branch September 5, 2023 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Breaking bug: Accessing the loop property while the loop is not running is not supported

4 participants