Skip to content

Conversation

@faviansamatha
Copy link
Contributor

@faviansamatha faviansamatha commented Dec 30, 2025

Description

  • Moved all class variable ThreadPoolExecutors to a centralized container.
  • Thread pools will now be initialized when needed.
  • Added static wrapper method to cleanup these resources explicitly
  • Updated documentation to call this new Wrapper.release_resources at the end of a program.

Related to #1055

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@faviansamatha faviansamatha force-pushed the chore/containerize-thread branch 3 times, most recently from 590b04e to 32a2b7f Compare December 31, 2025 01:29
@faviansamatha faviansamatha force-pushed the chore/containerize-thread branch from 32a2b7f to 8c02590 Compare December 31, 2025 01:32
@faviansamatha faviansamatha marked this pull request as ready for review January 2, 2026 17:25
```

> [!IMPORTANT]
> Always call both `AwsWrapperConnection.release_resources()` and `ThreadPoolContainer.release_resources()` at application shutdown to ensure:
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: is it not Wrapper.release_resources() and doesn't that call include ThreadPoolContainer.release_resources() so both don't need to be called. Also I believe it is an important distinction on whether this is called per connection or per application and should be explicitly said

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack I think this was a mistake, we should just be calling the Wrapper.relase 😓, and yea we don't need to call both

> 2. Client applications can manually call `MonitoringThreadContainer.clean_up()` to clean up any dangling resources.
> It is best practice to call `MonitoringThreadContainer.clean_up()` at the end of the application to ensure a graceful exit; otherwise, the application may wait until the `monitor_disposal_time_ms` has been passed before terminating. This is because the Python driver waits for all daemon threads to complete before exiting.
> 2. Client applications can manually call `aws_advanced_python_wrapper.release_resources()` to clean up any dangling resources.
> It is best practice to call `aws_advanced_python_wrapper.release_resources()` at the end of the application to ensure a graceful exit; otherwise, the application may wait until the `monitor_disposal_time_ms` has been passed before terminating. This is because the Python driver waits for all daemon threads to complete before exiting.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to update the sample code below to call aws_advanced_python_wrapper.release_resources() at the end

Copy link
Contributor

@karenc-bq karenc-bq Jan 5, 2026

Choose a reason for hiding this comment

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

Do users still need to call MonitoringThreadContainer.clean_up() with this change?
Seeing conflicting information as this doc removes MonitoringThreadContainer.clean_up() but we still call it in tests/unit/cleanup.py and tests/unit/test_monitor.py

Copy link
Contributor Author

@faviansamatha faviansamatha Jan 6, 2026

Choose a reason for hiding this comment

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

I updated the sample code. And they do not since it calls MonitoringThreadContainer.clean_up(). I changed tests in the next revision to use this instead. Users can still call MonitoringThreadContainer.clean_up() if they want, but it won't release the thread pool initialized in other classes

print("-- end of application")

# Clean up any remaining resources created by the plugins.
release_resources()
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why are some examples wrapped with try-finally some are not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just added it to the end when changing the examples. Ideally, they should be inside a try-finally since it will be cleaning up resources. I modified all the examples to reflect this in the next revision.

@faviansamatha faviansamatha force-pushed the chore/containerize-thread branch from 0310f1a to 529fee6 Compare January 6, 2026 20:16
@faviansamatha faviansamatha merged commit d13b509 into main Jan 6, 2026
19 of 20 checks passed
@faviansamatha faviansamatha deleted the chore/containerize-thread branch January 6, 2026 23:21
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.

3 participants