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

[python] Cleanup ThreadPool with atexit rather than __del__ #10002

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

fabianvf
Copy link

@fabianvf fabianvf commented Jan 22, 2020

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

This removes the __del__ function from the generated Python client,
and replaces it with a cleanup function. When a ThreadPool is created,
the cleanup function is registered with the atexit module.

This fixes #9991, where the API client could hang indefinitely at
garbage collection.

cc @kenjones-cisco

@fabianvf
Copy link
Author

@gaborbernat that might be the fastest review I've ever gotten, got it in while I was writing up the PR description. I think I addressed your comments

@gaborbernat
Copy link

I feel like maybe instead cleanup should be close and we should now also allow to call the client with the with statement, so it may cleanup automatically whenever the user no longer needs it.

This removes the `__del__` function from the generated Python client,
and replaces it with a `cleanup` function. When a ThreadPool is created,
the cleanup function is registered with the `atexit` module.

This fixes swagger-api#9991, where the API client could hang indefinitely at
garbage collection.
@fabianvf
Copy link
Author

@gaborbernat renamed cleanup to close, think making it a context manager might be a bit out of scope for this bugfix but I can make a followup PR for it

@anichari
Copy link

Hello, has this been merged and available in the latest codegen packages? I tried a few things with codegen versions but I still dont see this change in the api_client.py generated files.

  1. I used 2.0.14-SNAPSHOT (built from master) and with that code, I still see the lazy init of ThreadPool rather than the newer code that creates the ThreadPool in init.
  2. I used 3.0.19 (brew installed) and with that, the del method is still there, no sign of above changes to api_client.py in that either.

@gaborbernat
Copy link

Nope, we've moved on to use OpenAPITools/openapi-generator#5094 instead, that contains the fix. Swagger never addressed this issue.

@anichari
Copy link

Nope, we've moved on to use OpenAPITools/openapi-generator#5094 instead, that contains the fix. Swagger never addressed this issue.

Thx much

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.

[Python] Generated code is out of contract - application hangs indefinitely
4 participants