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

ident_func when running within gunicorn+gaiohttp #730

Closed
urbaniak opened this issue Apr 26, 2015 · 7 comments
Closed

ident_func when running within gunicorn+gaiohttp #730

urbaniak opened this issue Apr 26, 2015 · 7 comments

Comments

@urbaniak
Copy link

LocalManager.ident_func should be set to asyncio.Task.current_task when running under gunicorn+gaiohttp.

Currently if we're running with gaiohttp the LocalManager mixes the context of different tasks :(

Have no idea how to properly implement the detection if we're running under eventlet (under python3) or asyncio, just hacked my own greenlet module which returns the proper task id.

@RonnyPfannschmidt
Copy link
Contributor

the default is only aware of greenlets/threads, its unclear how to deal with something more complex

LocalManager can be given a custom ident function in the constructor, but its unclear how to determine the deployment situation

@urbaniak
Copy link
Author

Maybe we can combine all available task identifiers?

Something like that:

identifiers = []

try:
    from greenlet import getcurrent
    identifiers.append(getcurrent)
except ImportError:
    pass

try:
    from thread import get_ident
    identifiers.append(get_ident)
except ImportError:
    pass

try:
    from asyncio.Task import current_task
    identifiers.append(current_task)
except ImportError:
    pass


def identifier():
    return "".join([str(i()) for i in identifiers])

@untitaker
Copy link
Contributor

I don't like the performance implications of that.

I suppose if e.g. greenlet.getcurrent raises an exception if greenlet is not used, we could pop it from identifiers, and that could improve performance a bit again, but there's still some penalty left.

@untitaker
Copy link
Contributor

I wonder if we could use threading.active_count to determine whether to disable the usage of threading.get_ident, and if the other libs support something similar.

@urbaniak
Copy link
Author

Similar thing can be achieved by using asyncio.get_event_loop().is_running() on asyncio.

@urbaniak
Copy link
Author

urbaniak commented Dec 8, 2015

Any chances to get that one resolved somehow?

We can determine which eventloop is used just once at the startup, that won't cause any performance issues.

@davidism
Copy link
Member

davidism commented Nov 26, 2018

Sounds like it's already customizable. Any better detection will happen as we add support for ASGI, rolling this into #1322

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants