Using ray with textual (a python tui library) locks up

How severe does this issue affect your experience of using Ray?

  • High: It blocks me to complete my task.

I’ve been developing some simulations using ray core’s Actors. They are fantastic and make life very easy. I’m now trying to connect this work to a simple user interface written using textual, a tui library for python. https://textual.textualize.io.

However, calling ray.init() locks the application up, even in the most basic apps such as:

from textual.app import App, ComposeResult
from textual.widgets import Footer, Header
import ray


class StopwatchApp(App):
    """A Textual app to manage stopwatches."""

    BINDINGS = [("d", "toggle_dark", "Toggle dark mode")]

    def compose(self) -> ComposeResult:
        """Create child widgets for the app."""
        yield Header()
        yield Footer()

    def action_toggle_dark(self) -> None:
        """An action to toggle dark mode."""
        self.dark = not self.dark


if __name__ == "__main__":
    ray.init()
    app = StopwatchApp()
    app.run()
    ray.shutdown()

Comment out the ray.init() / ray.shutdown() and it works fine.
If I run ray run start --head first, at the command-line, then the app works fine.
Which suggests to me there is something going in a ray.init() when there is no existing cluster that somehow kills textual.

The app I’m building should just be self-contained, so running ray commands separately is not an option.

Does someone have any idea what might be causing the problem?

Thanks,
Brett

if you define StopwatchApp and import relevant modules after calling ray.init , does it work? It could be related textual doing something interesting in the global context, and it doesn’t play well with ray. Can you try ^?