Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workers report RUNNING state twice #4670

Closed
Joe-TheBro opened this issue Jun 22, 2024 · 4 comments
Closed

Workers report RUNNING state twice #4670

Joe-TheBro opened this issue Jun 22, 2024 · 4 comments

Comments

@Joe-TheBro
Copy link

Have you checked closed issues? https://github.com/Textualize/textual/issues?q=is%3Aissue+is%3Aclosed
Yes

The worker reports a RUNNING state when PENDING, causing a double report when the worker is actually in a RUNNING state.
image

There is no error shown on the command line, and TUI launches fine.

I'm wondering if this is the intended behavior, as I wrote some code similar to the code below surrounding the Worker.StateChanged event.

def on_worker_state_changed(self, event: Worker.StateChanged) -> None:
        worker_name = event.worker.name
        worker_state = str(event.worker.state).split(".")[1]
        self.log(event.worker.state)
        match worker_name:
            case "get_arduino":
                match worker_state:
                    case "PENDING":
                        pass
                    case "RUNNING":
                        pass
                    case "CANCELLED":
                        pass
                    case "ERROR":
                        pass
                    case "SUCCESS":
                        pass

Textual Diagnostics

Versions

Name Value
Textual 0.67.1
Rich 13.7.1

Python

Name Value
Version 3.12.3
Implementation CPython
Compiler MSC v.1938 64 bit (AMD64)
Executable \env\python.exe

Operating System

Name Value
System Windows
Release 11
Version 10.0.22631

Terminal

Name Value
Terminal Application vscode (1.90.1)
TERM Not set
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=159, height=27
legacy_windows False
min_width 1
max_width 159
is_terminal True
encoding utf-8
max_height 27
justify None
overflow None
no_wrap False
highlight None
markup None
height None
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@willmcgugan
Copy link
Collaborator

willmcgugan commented Jun 23, 2024

I suspect what you are seeing is that by the time the event is received, the state has change.

The StateChange event has a state property that contains the state when the event was posted. If you log that, you may find it works as expected.

@Joe-TheBro
Copy link
Author

I appreciate the quick response. This was exactly what I was looking for. I realize now that when I set worker_state = event.worker.state, it was referencing the worker itself. Because that takes time, there is no guarantee that it will be the state advertised in the event. Thanks!

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

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

No branches or pull requests

2 participants