dabeaz / curio

Good Curio!
Other
4.02k stars 241 forks source link

Use of kqueue in kernel.py #234

Closed nberrios closed 6 years ago

nberrios commented 6 years ago

In curio/kernel.py there is the disclaimer:

# kqueue is the datatype used by the kernel for all of its queuing functionality.
# Any time a task queue is needed, use this type instead of directly hard-coding the
# use of a deque.  This will make sure the code continues to work even if the
# queue type is changed later.

kqueue = deque

I noticed however that the wake and sleeping queues are not following the same design. See:

        self._wake_queue = deque()

        # Sleeping task queue
self._sleeping = []

If this is intentional, could someone briefly explain why the wake/sleep queues need to be handled differently than the ready queue? Thanks

dabeaz commented 6 years ago

The kqueue structure is used in determining which task will run next in the kernel scheduler. Right now it's a deque(), but it could be changed to something else should priority queuing be added.

_wake_queue and _sleeping are internal data structures used for a different purpose than task scheduling decisions. _wake_queue contains tasks awakened by the completion of Futures in separate execution threads. _sleeping is used to manage time (and in the current version of Curio is replaced by a special TimeQueue class).

nberrios commented 6 years ago

Ah, I see! Thanks for the speedy response, Dave. Closing this question

kdart commented 6 years ago

Although the kqueue name can be a little confusing if you're familiar with BSD kernels. ;-)

dabeaz commented 6 years ago

I'd agree on the kqueue name. Honestly, the whole 'kqueue' thing was used more in earlier versions of Curio, but was abandoned to focus on more varied kinds of scheduling primitives. Maybe I'll just delete this.