Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

Add notion of context_id to event loop #165

Closed
GoogleCodeExporter opened this issue Apr 10, 2015 · 6 comments
Closed

Add notion of context_id to event loop #165

GoogleCodeExporter opened this issue Apr 10, 2015 · 6 comments

Comments

@GoogleCodeExporter
Copy link

It's crucial to have an analogue of threadlocal object for coroutines. Tools 
like newrelic use it to provide deep performance analysis, web developers need 
to know details about the current request being served etc.

The proposed solution to this problem is to add an API to set a context_id when 
asyncio.Task is created. This context_id will then be automatically assigned to 
all callbacks, futures and tasks the original task has given birth to.

Original issue reported on code.google.com by yseliva...@gmail.com on 15 Apr 2014 at 7:50

@GoogleCodeExporter
Copy link
Author

Patch review: https://codereview.appspot.com/87940044

Original comment by yseliva...@gmail.com on 15 Apr 2014 at 7:53

@GoogleCodeExporter
Copy link
Author

As I told you at Pycon, a nice use case of that would be to store (somewhere 
using this context identifier) the IP address of a request. I needed that in a 
Twisted project using an XML-RPC server, we had to know the IP address to check 
to security: restrict a cookie to a single IPv4 address.

Original comment by victor.s...@gmail.com on 16 Apr 2014 at 4:29

@GoogleCodeExporter
Copy link
Author

I have a new patch, completely different and much much smaller. Will upload it 
tomorrow.

Original comment by yseliva...@gmail.com on 16 Apr 2014 at 4:40

@GoogleCodeExporter
Copy link
Author

Contexts may help to implement the issue #73: set the name of a task.

Original comment by victor.s...@gmail.com on 19 Jun 2014 at 3:36

@GoogleCodeExporter
Copy link
Author

Yeah, that'll be totally doable. 
I'm going to return to the codereview/patch discussion of this issue soon.

Original comment by yseliva...@gmail.com on 19 Jun 2014 at 4:32

@GoogleCodeExporter
Copy link
Author

With the new 'Loop.create_task' method it's totally possible to have this 
feature without monkey patching asyncio core objects. Just subclass Task and 
add the logic from https://codereview.appspot.com/87940044 to its constructor.

I think we can close this ticket for now, until we want this supported in 
asyncio core natively. Or until we need to have context_id working on a lower 
level than Tasks.

Thanks a lot to all for your reviews!

Original comment by yseliva...@gmail.com on 12 Sep 2014 at 10:49

  • Changed state: WontFix

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

No branches or pull requests

1 participant