As someone who uses channels all the time (in Nim) for cross-thread comms, this is pretty exciting. The deep-copy that Nim channels do makes things simpler at the cost of more memory allocations obviously, but even on an ESP32-S3 it's been a great abstraction. Of course I get to cheat and use actual shared memory with FreeRTOS semaphores/mutexes and such when its really required, but having channels as the first-class easy-to-use mechanism is the right move in my opinion (which is worth about as much as you just paid for it, of course)
> Along those same lines, we will initially restrict the types that may be passed through channels to the following:
> * None
> * bytes
> * str
> * int
> * channels
> Limiting the initial shareable types is a practical matter, reducing the potential complexity of the initial implementation.
That's a really interesting detail - presumably channels can be passed so you can do callbacks ("reply on this other channel").
I wonder why floats aren't on that list? I know they're more complex than ints, but I would expect they would still end up with a relatively simple binary representation.
I don’t know why floats aren’t included, but any float can be easily represented by an int with same bits, or a bytestring, using the struct module to convert between them, so there are clear workarounds.
Re:Faster CPython 3.12 Plan
by tylercrompton on Tuesday September 20, 2022 @12:47AM
(#32907764)
Fun fact, floats are easier than `int` because `float` has a predictable size.
Re:Faster CPython 3.12 Plan
by JoshTriplett on Tuesday September 20, 2022 @09:29AM
(#32911403)
> That's a really interesting detail - presumably channels can be passed so you can do callbacks ("reply on this other channel").
Callbacks or notifications, yes. I use both patterns quite often.
Sounds like an oversight…
Passing channels over other channels used to be a reasonably standard trick in Go, IIRC.
Re:Faster CPython 3.12 Plan
by yeswecatan on Monday September 19, 2022 @11:27PM
(#32907314)
Any idea what a "channel" actually is/how it is implemented?
> Regarding the proposed solution, “channels”, it is a basic, opt-in data sharing mechanism that draws inspiration from pipes, queues, and CSP’s channels.
> As simply described earlier by the API summary, channels have two operations: send and receive. A key characteristic of those operations is that channels transmit data derived from Python objects rather than the objects themselves. When objects are sent, their data is extracted. When the “object” is received in the other interpreter, the data is converted back into an object owned by that interpreter.
https://peps.python.org/pep-0554/#shared-data