mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-06 01:46:10 +00:00
[python] Cleanup ThreadPool with atexit rather than __del__ (#5094)
* [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
This commit is contained in:
committed by
GitHub
parent
d627282e89
commit
15345e1620
@@ -30,15 +30,17 @@ import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi()
|
||||
body = petstore_api.User() # User | Created user object
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient() as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi(api_client)
|
||||
body = petstore_api.User() # User | Created user object
|
||||
|
||||
try:
|
||||
# Create user
|
||||
api_instance.create_user(body)
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->create_user: %s\n" % e)
|
||||
try:
|
||||
# Create user
|
||||
api_instance.create_user(body)
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->create_user: %s\n" % e)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
@@ -81,15 +83,17 @@ import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi()
|
||||
body = [petstore_api.User()] # list[User] | List of user object
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient() as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi(api_client)
|
||||
body = [petstore_api.User()] # list[User] | List of user object
|
||||
|
||||
try:
|
||||
# Creates list of users with given input array
|
||||
api_instance.create_users_with_array_input(body)
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->create_users_with_array_input: %s\n" % e)
|
||||
try:
|
||||
# Creates list of users with given input array
|
||||
api_instance.create_users_with_array_input(body)
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->create_users_with_array_input: %s\n" % e)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
@@ -132,15 +136,17 @@ import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi()
|
||||
body = [petstore_api.User()] # list[User] | List of user object
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient() as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi(api_client)
|
||||
body = [petstore_api.User()] # list[User] | List of user object
|
||||
|
||||
try:
|
||||
# Creates list of users with given input array
|
||||
api_instance.create_users_with_list_input(body)
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->create_users_with_list_input: %s\n" % e)
|
||||
try:
|
||||
# Creates list of users with given input array
|
||||
api_instance.create_users_with_list_input(body)
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->create_users_with_list_input: %s\n" % e)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
@@ -185,15 +191,17 @@ import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi()
|
||||
username = 'username_example' # str | The name that needs to be deleted
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient() as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi(api_client)
|
||||
username = 'username_example' # str | The name that needs to be deleted
|
||||
|
||||
try:
|
||||
# Delete user
|
||||
api_instance.delete_user(username)
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->delete_user: %s\n" % e)
|
||||
try:
|
||||
# Delete user
|
||||
api_instance.delete_user(username)
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->delete_user: %s\n" % e)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
@@ -237,16 +245,18 @@ import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi()
|
||||
username = 'username_example' # str | The name that needs to be fetched. Use user1 for testing.
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient() as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi(api_client)
|
||||
username = 'username_example' # str | The name that needs to be fetched. Use user1 for testing.
|
||||
|
||||
try:
|
||||
# Get user by user name
|
||||
api_response = api_instance.get_user_by_name(username)
|
||||
pprint(api_response)
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->get_user_by_name: %s\n" % e)
|
||||
try:
|
||||
# Get user by user name
|
||||
api_response = api_instance.get_user_by_name(username)
|
||||
pprint(api_response)
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->get_user_by_name: %s\n" % e)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
@@ -291,17 +301,19 @@ import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi()
|
||||
username = 'username_example' # str | The user name for login
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient() as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi(api_client)
|
||||
username = 'username_example' # str | The user name for login
|
||||
password = 'password_example' # str | The password for login in clear text
|
||||
|
||||
try:
|
||||
# Logs user into the system
|
||||
api_response = api_instance.login_user(username, password)
|
||||
pprint(api_response)
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->login_user: %s\n" % e)
|
||||
try:
|
||||
# Logs user into the system
|
||||
api_response = api_instance.login_user(username, password)
|
||||
pprint(api_response)
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->login_user: %s\n" % e)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
@@ -346,14 +358,16 @@ import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi()
|
||||
|
||||
try:
|
||||
# Logs out current logged in user session
|
||||
api_instance.logout_user()
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->logout_user: %s\n" % e)
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient() as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi(api_client)
|
||||
|
||||
try:
|
||||
# Logs out current logged in user session
|
||||
api_instance.logout_user()
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->logout_user: %s\n" % e)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
@@ -395,16 +409,18 @@ import petstore_api
|
||||
from petstore_api.rest import ApiException
|
||||
from pprint import pprint
|
||||
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi()
|
||||
username = 'username_example' # str | name that need to be deleted
|
||||
# Enter a context with an instance of the API client
|
||||
with petstore_api.ApiClient() as api_client:
|
||||
# Create an instance of the API class
|
||||
api_instance = petstore_api.UserApi(api_client)
|
||||
username = 'username_example' # str | name that need to be deleted
|
||||
body = petstore_api.User() # User | Updated user object
|
||||
|
||||
try:
|
||||
# Updated user
|
||||
api_instance.update_user(username, body)
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->update_user: %s\n" % e)
|
||||
try:
|
||||
# Updated user
|
||||
api_instance.update_user(username, body)
|
||||
except ApiException as e:
|
||||
print("Exception when calling UserApi->update_user: %s\n" % e)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
Reference in New Issue
Block a user