pytdml icon indicating copy to clipboard operation
pytdml copied to clipboard

Resource initialization

Open photonbit opened this issue 9 months ago • 1 comments

One of the points to take a look is to avoid creating heavy and synchronization objects on import.

For example, inside datalibrary.downloader a multiprocessing.Lock is created on import, and inside datalibrary.s3Client a MinioClient is created with a special case in the init method to provide test configuration.

At the same time, in pytdml.io.S3_reader, we import boto3 inside the init method of S3Client and wrap the import in a try block, when boto3 is a dependency of the project, and it doesn't seem to be a reason not to make the import in the top level of the file.

Other similar cases could be investigated during the code sprint.

photonbit avatar Mar 13 '25 15:03 photonbit

We do have a lot of work to do regarding potential performance waste and maintenance issues. 

  1. Global Code Review: Check all modules for side-effect code (e.g., functions executed on import), hidden dependencies, or unnecessary environment-specific branches. ​
  2. Tool-Driven Standards: Integrate flake8 or pylint rules to detect non-compliant imports and unused dependencies.  By ​lazy initializing resources, ​explicitly managing dependencies, and ​decoupling configuration logic, we can resolve potential performance waste and maintenance issues, improving code maintainability and stability.

Relifest avatar Mar 20 '25 08:03 Relifest