Visitar URL original
[WIP] Uvhandle context by fantix · Pull Request #348 · MagicStack/uvloop · GitHub
The Wayback Machine - https://web.archive.org/web/20200906154435/https://github.com/MagicStack/uvloop/pull/348/
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

[WIP] Uvhandle context #348

Draft
wants to merge 3 commits into
base: master
from
Draft

Conversation

@fantix
Copy link
Member

fantix commented May 25, 2020 •

  • +- UVAsync (async_)
  • +- UVCheck (check)
  • +- UVIdle (idle)
  • +- UVPoll (poll)
  • +- UVProcess (process)
  • | +- UVProcessTransport (process)
  • +- UVSocketHandle (handle)
  • | +- UVBaseTransport (basetransport)
  • | | +- UDPTransport (udp)
  • | | +- UVStream (stream)
  • | | +- TCPTransport (tcp)
  • | | +- UnixTransport (pipe)
  • | | +- ReadUnixTransport (pipe)
  • | | +- WriteUnixTransport (pipe)
  • | +- UVStreamServer (streamserver)
  • | +- TCPServer (tcp)
  • | +- UnixServer (pipe)
  • +- UVTimer (timer)
@1st1
Copy link
Member

1st1 commented May 25, 2020

My memory here is a little rusty, but can we instead change

uvloop/uvloop/cbhandles.pyx

Lines 338 to 421 in 465717f

cdef new_Handle(Loop loop, object callback, object args, object context):
cdef Handle handle
handle = Handle.__new__(Handle)
handle._set_loop(loop)
handle._set_context(context)
handle.cb_type = 1
handle.arg1 = callback
handle.arg2 = args
return handle
cdef new_MethodHandle(Loop loop, str name, method_t callback, object ctx):
cdef Handle handle
handle = Handle.__new__(Handle)
handle._set_loop(loop)
handle._set_context(None)
handle.cb_type = 2
handle.meth_name = name
handle.callback = <void*> callback
handle.arg1 = ctx
return handle
cdef new_MethodHandle1(Loop loop, str name, method1_t callback,
object ctx, object arg):
cdef Handle handle
handle = Handle.__new__(Handle)
handle._set_loop(loop)
handle._set_context(None)
handle.cb_type = 3
handle.meth_name = name
handle.callback = <void*> callback
handle.arg1 = ctx
handle.arg2 = arg
return handle
cdef new_MethodHandle2(Loop loop, str name, method2_t callback, object ctx,
object arg1, object arg2):
cdef Handle handle
handle = Handle.__new__(Handle)
handle._set_loop(loop)
handle._set_context(None)
handle.cb_type = 4
handle.meth_name = name
handle.callback = <void*> callback
handle.arg1 = ctx
handle.arg2 = arg1
handle.arg3 = arg2
return handle
cdef new_MethodHandle3(Loop loop, str name, method3_t callback, object ctx,
object arg1, object arg2, object arg3):
cdef Handle handle
handle = Handle.__new__(Handle)
handle._set_loop(loop)
handle._set_context(None)
handle.cb_type = 5
handle.meth_name = name
handle.callback = <void*> callback
handle.arg1 = ctx
handle.arg2 = arg1
handle.arg3 = arg2
handle.arg4 = arg3
return handle
to automatically capture the current context?

@fantix
Copy link
Member Author

fantix commented May 26, 2020

Maybe yes - they're intended to bridge the native callbacks anyways, right? Submitted a commit to try this approach. I had to hack in the arg2 value before calling _run().

@1st1
Copy link
Member

1st1 commented May 26, 2020

Maybe yes - they're intended to bridge the native callbacks anyways, right? Submitted a commit to try this approach. I had to hack in the arg2 value before calling _run().

I think we need parallel APIs like new_MethodHandleNWithContext.

@1st1
Copy link
Member

1st1 commented May 26, 2020

Or add a trailing argument to all new_MethodHandleN methods which can be either a context, or a boolean with True/False, with True meaning "copy the current context", and False meaning run in empty context. As I said my knowledge of the code base is a bit rusty, but I believe that this is a way better approach than to handle context in UVHandles.

@fantix
Copy link
Member Author

fantix commented May 26, 2020

Got it, that makes sense - I'll then try to propose something more complete.

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

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.