[Feature Request] Worker instance lifespan
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().
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.
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?
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.
Closing, but feel free to keep discussing or reopen @funkindy.