Python & Go

sturlamolden sturlamolden at yahoo.no
Mon Nov 16 12:05:13 CET 2009


On 16 Nov, 10:06, Terry Reedy <tjre... at udel.edu> wrote:

> > Python run well on multiple cores, you just have to use processes
> > instead of threads.
>
> But not so trivially as to add one word to an existing function.
> Hence by tweak, I meant, as explained in another post, to add a keyword
> or just a decorator that will do what the go keyword does in go.

A decorator function like @go could just call os.fork and run the
function in the child. We already have a between-process Queue in
multiprocessing to use as channels.

Or we could have a context manager that forks in __enter__ and
waitpids or exits in __exit__. The body of the with-statement would
then be executed in the child process, the parent would just raise an
exception to skip directly to __exit__.

Not rocket science as all. Yes that would give us a new isolated
process, but such isolation is present in Erlang as well.

(Windows is more tricky though, as there is no efficent fork.)

































More information about the Python-list mailing list