c.Kubespawner.modify_pod_hook does not support co-routines
See original GitHub issueBug description
I am facing an issue when providing a co-routine to c.Kubespawner.modify_pod_hook
.
The Tornado docs for gen.maybe_future()
say that maybe_future
can only handle Futures and no other yieldable objects.
Does this mean, we can pass coros as a hook function?
I mean a coro which as been declared via async def ...
Expected behaviour
c.Kubespawner.modify_pod_hook
should support co-routines.
Actual behaviour
c.Kubespawner.modify_pod_hook
only supports normal functions or futures.
If passed a co-routine, I will pass the co-routine into the Kubernetes client which fails.
How to reproduce
- Define a co-routine via the
async def
syntax:
import asyncio
async def my_pod_modify_hook(spawner):
await asyncio.sleep(1)
return
c.Kubespawner.modify_pod_hook = my_pod_modify_hook
Your personal set up
A pretty standard Z2JH setup (master)
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
jupyterhub_config.py - Kubespawner - Read the Docs
A JupyterHub spawner that spawn pods in a Kubernetes Cluster. Each server spawned by a user will have its own KubeSpawner instance. after_pod_created_hook...
Read more >Kubespawner Documentation - Read the Docs
Kubernetes is an open-source system for automating deployment, scaling, and management of containerized appli- cations.
Read more >KubeSpawner and LDAPauthentication run under users LDAP ...
Now though, it seems that the singleuser.defaultUrl in the Z2JH config is no longer used. I've tried a few different ways to set...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes! That’s the right thing to do.
If you want, though, I don’t think kubespawner needs to be as fully general as jupyterhub’s own implementation, which aims for maximum compatibility to ensure it didn’t break anything when we made the big asyncio transition. If you are a little more strict about what things may return, you can even optimize a bit by avoiding the unnecessary
await
if it’s not awaitable:The only case that won’t handle is
concurrent.futures
which is not really important to handle yourself because it’s only asking the author of the function to addasyncio.wrap_future()
on the end before returning it to kubespawner, if they happen to be using thread pools (tornado’s@run_in_executor
helper already does this). The only reason jupyterhub handles this is tornado’s maybe_future handled it before and we wanted to make sure nothing broke.Or, alternately, for APIs that should always return None:
which is an even cheaper check than
isawaitable()
:x is None
~ 30nsinspect.isawaitable(x)
~ 700nsjupyterhub.utils.maybe_future(x)
~ 2µs (not counting extra await for non-async callables)(all these timescales are negligible when adding kubernetes API requests to the mix)
Yes, I would support this. I could also submit a PR 😃