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

No way to release pool connection when using decorator and aiohttp #352

Closed
kivsiak opened this issue Oct 30, 2017 · 4 comments
Closed

No way to release pool connection when using decorator and aiohttp #352

kivsiak opened this issue Oct 30, 2017 · 4 comments
Labels

Comments

@kivsiak
Copy link

kivsiak commented Oct 30, 2017

When i use @cache decorator in my aiohttp application and close app using ctrl-C i got this message in output:

Task was destroyed but it is pending!

Not critical, but dirty. Is there any way to clear close all connection and courtines? In aiohttp cleanup handler?

@argaen
Copy link
Member

argaen commented Oct 30, 2017

Hi @kivsiak, yup its a known issue. There is manual way of doing this if you really need it.

Any function that you decorate will have an attribute called cache: https://github.com/argaen/aiocache/blob/master/aiocache/decorators.py#L50. In your cleanup handler, you can do `await my_decorated_function.close().

@kivsiak
Copy link
Author

kivsiak commented Oct 31, 2017

Hello @argaen, looks like i'm bad at decoration, usualy i use this way to add attrs: https://gist.github.com/kivsiak/9a2b5965ee3fd40c8c4b072e160a63cf

Here the gist of my way of using @cached decorator:

https://gist.github.com/kivsiak/b2fc47008f1cdc01bd4d08359ccfc2d8

cached_call after decoration have no _cache, cache, close() attributes.

@argaen
Copy link
Member

argaen commented Nov 1, 2017

You are right, with the current implementation the cache is not accessible through the decorated function.

By adding a wrapper.cache = self.cache in https://github.com/argaen/aiocache/blob/master/aiocache/decorators.py#L67 should be enough.

Do you want to provide MR for this? (should include tests + docs updated).

@argaen
Copy link
Member

argaen commented Nov 6, 2017

Next release this will be avaible as function.cache

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

No branches or pull requests

2 participants