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

[CI] Fix: flake8 rule B109: Using the functools.lru_cache and functools.cache decorators on methods can lead to memory leaks #48186

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

win5923
Copy link
Contributor

@win5923 win5923 commented Oct 22, 2024

Why are these changes needed?

While running the pre-commit hook of flake8, the following error occurs if Python version is 3.12. It's because the version of flake8 is too old.

image

version:

  • python: 3.12.7
  • flake8: 7.1.1
  • flake8-bugbear: 24.8.19

Related issue number

Closes #48066

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

@win5923 win5923 marked this pull request as draft October 22, 2024 13:43
@win5923 win5923 force-pushed the flake8/B019 branch 2 times, most recently from 575af7c to 9e01cba Compare October 22, 2024 13:55
@win5923
Copy link
Contributor Author

win5923 commented Oct 22, 2024

@MortalHappiness PTAL

Signed-off-by: win5923 <ken89@kimo.com>
@win5923 win5923 marked this pull request as ready for review October 22, 2024 14:01
@MortalHappiness
Copy link
Member

MortalHappiness commented Oct 29, 2024

I wonder if the functools.cache here has no effect at all. As far as I know, functools.cache only caches function arguments, but this method has no arguments except for self.

Maybe the original author intended to use functools.cached_property, but I am not sure.

cc @rynewang

@rynewang
Copy link
Contributor

@bveeramani can you take a look at this issue and see if we want to change this cache?

@rynewang rynewang enabled auto-merge (squash) October 29, 2024 22:11
@github-actions github-actions bot added the go add ONLY when ready to merge, run all tests label Oct 29, 2024
@rynewang rynewang merged commit dc52ba4 into ray-project:master Oct 29, 2024
7 checks passed
@MortalHappiness
Copy link
Member

MortalHappiness commented Oct 30, 2024

@bveeramani Hi why is this PR merged? I thought you intended to use functools.cached_property right?

@win5923 win5923 deleted the flake8/B019 branch October 30, 2024 01:13
MortalHappiness added a commit to MortalHappiness/ray that referenced this pull request Oct 30, 2024
… functools.cache decorators on methods can lead to memory leaks (ray-project#48186)"

This reverts commit dc52ba4.

Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
@bveeramani
Copy link
Member

I wonder if the functools.cache here has no effect at all. As far as I know, functools.cache only caches function arguments, but this method has no arguments except for self.

The intention is that we'd only compute the values once per instance (i.e., for each value of self). Is that not the behavior with functools.cache?

@MortalHappiness
Copy link
Member

@bveeramani In Python, it’s more common to use functools.cached_property to cache methods with no arguments.

See https://docs.python.org/3/faq/programming.html#faq-cache-method-calls for details.

Jay-ju pushed a commit to Jay-ju/ray that referenced this pull request Nov 5, 2024
…ls.cache decorators on methods can lead to memory leaks (ray-project#48186)

While running the pre-commit hook of flake8, the following error occurs
if Python version is 3.12. It's because the version of flake8 is too
old.


![image](https://github.com/user-attachments/assets/bf56370f-04d7-4b9a-aea9-e1c578547ed4)


version:
- python: 3.12.7
- flake8: 7.1.1 
- flake8-bugbear: 24.8.19


Signed-off-by: win5923 <ken89@kimo.com>
jjyao pushed a commit that referenced this pull request Nov 7, 2024
…48436)

Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
JP-sDEV pushed a commit to JP-sDEV/ray that referenced this pull request Nov 14, 2024
…ls.cache decorators on methods can lead to memory leaks (ray-project#48186)

While running the pre-commit hook of flake8, the following error occurs
if Python version is 3.12. It's because the version of flake8 is too
old.


![image](https://github.com/user-attachments/assets/bf56370f-04d7-4b9a-aea9-e1c578547ed4)


version:
- python: 3.12.7
- flake8: 7.1.1 
- flake8-bugbear: 24.8.19


Signed-off-by: win5923 <ken89@kimo.com>
JP-sDEV pushed a commit to JP-sDEV/ray that referenced this pull request Nov 14, 2024
…` instead (ray-project#48436)

Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
mohitjain2504 pushed a commit to mohitjain2504/ray that referenced this pull request Nov 15, 2024
…ls.cache decorators on methods can lead to memory leaks (ray-project#48186)

While running the pre-commit hook of flake8, the following error occurs
if Python version is 3.12. It's because the version of flake8 is too
old.

![image](https://github.com/user-attachments/assets/bf56370f-04d7-4b9a-aea9-e1c578547ed4)

version:
- python: 3.12.7
- flake8: 7.1.1
- flake8-bugbear: 24.8.19

Signed-off-by: win5923 <ken89@kimo.com>
Signed-off-by: mohitjain2504 <mohit.jain@dream11.com>
mohitjain2504 pushed a commit to mohitjain2504/ray that referenced this pull request Nov 15, 2024
…` instead (ray-project#48436)

Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
Signed-off-by: mohitjain2504 <mohit.jain@dream11.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix flake8 rule B019
4 participants