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

[Feature Request] Worker instance lifespan #666

Open
funkindy opened this issue Oct 10, 2024 · 3 comments
Open

[Feature Request] Worker instance lifespan #666

funkindy opened this issue Oct 10, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@funkindy
Copy link

It would be nice to have some kind of lifespan for worker instances.

In my case i need shared http client (httpx.AsyncClient) for my activities, and i now don't see a proper place to call await client.aclose().

@funkindy funkindy added the enhancement New feature or request label Oct 10, 2024
@cretz
Copy link
Member

cretz commented Oct 10, 2024

Can you clarify the request a bit? A worker is running and using what it has until run returns (or if you're using async with, until that block is done). A worker's run does not return until it is shutdown and all activities are done (see https://github.com/temporalio/sdk-python?tab=readme-ov-file#worker-shutdown). You should add your client close after the worker run is complete.

@funkindy
Copy link
Author

async with has its own complex cleanup logic, which i have to reproduce in my scenario without context manager.

Why not to include the implementation of __aexit__ to some kind of asynd def cleanup(...)? Or maybe worker.shutdown is sufficient?

@cretz
Copy link
Member

cretz commented Oct 15, 2024

Why not to include the implementation of aexit to some kind of asynd def cleanup(...)? Or maybe worker.shutdown is sufficient?

Worker shutdown should be sufficient. If you add your cleanup code after worker is shutdown (or after context manager is complete), that is enough to guarantee the worker isn't using things anymore. A worker lifetime is the life of its run or context manager, both will not complete while any activities are still running (neither will the shutdown call), add any cleanup after that as needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants