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] Generated code is out of contract - application hangs indefinitely #5093

Closed
fabianvf opened this issue Jan 23, 2020 · 0 comments · Fixed by #5094
Closed

[Python] Generated code is out of contract - application hangs indefinitely #5093

fabianvf opened this issue Jan 23, 2020 · 0 comments · Fixed by #5094

Comments

@fabianvf
Copy link
Contributor

Bug originally reported by @gaborbernat in the swagger-codegen project, but the same issue applies here: swagger-api/swagger-codegen#9991

The generated code snippet from - https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/python/api_client.mustache#L78 is not allowed:

def __del__(self):
    if self._pool is not None:
        self._pool.close()
        self._pool.join()

The very simple program of creating a global client, and then just exiting will hang indefinitely on Python3.8. Initially raised as CPython bug under https://bugs.python.org/issue39360, but @pablogsal (core CPython developer) investigated and concluded that this way of cleaning up pools is not supported. Instead one should either allow the user to close or if the user did not do the generated code should do by registering https://docs.python.org/3.8/library/atexit.html callbacks.

Fix incoming

fabianvf added a commit to fabianvf/openapi-generator that referenced this issue Jan 23, 2020
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 OpenAPITools#5093, where the API client could hang indefinitely at
garbage collection.
spacether pushed a commit that referenced this issue Jan 29, 2020
* [python] Cleanup ThreadPool with atexit rather than __del__

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 #5093, where the API client could hang indefinitely at
garbage collection.

* Update petstore examples

* Test to ensure threadpool is cleaned up

* Docs now encourage using the context manager

* Regenerate docs

* Update samples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants