News for hackers. Stuff that matters.
Re:Faster CPython 3.12 Plan by theandrewbailey on Monday September 19, 2022 @09:10PM (#32906395)
> There are a number of valid solutions, several of which may be appropriate to support in Python. This proposal provides a single basic solution: “channels”. Ultimately, any other solution will look similar to the proposed one, which will set the precedent. Note that the implementation of Interpreter.run() will be done in a way that allows for multiple solutions to coexist, but doing so is not technically a part of the proposal here.

> 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

Re:Faster CPython 3.12 Plan by girvo on Monday September 19, 2022 @10:32PM (#32906990)
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)
Re:Faster CPython 3.12 Plan by simonw on Monday September 19, 2022 @09:47PM (#32906658)
> 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.

Re:Faster CPython 3.12 Plan by galonk on Monday September 19, 2022 @09:58PM (#32906728)
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.

Re:Faster CPython 3.12 Plan by saagarjha on Monday September 19, 2022 @10:06PM (#32906788)
Sounds like an oversight…
Re:Faster CPython 3.12 Plan by nine_k on Tuesday September 20, 2022 @12:46AM (#32907754)
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?
Re:Faster CPython 3.12 Plan by znpy on Tuesday September 20, 2022 @05:09AM (#32909396)
Wild guess, a double-ended queue guarded by some kind of locking mechanism ?