9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] python csp
@ 2009-03-11 16:58 roger peppe
  2009-03-11 17:13 ` gdiaz
  0 siblings, 1 reply; 12+ messages in thread
From: roger peppe @ 2009-03-11 16:58 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

apologies for the off topic email, but i find myself
in the situation of having to run up a web frontend
using python - does if anyone here know
of a decent plan9-style CSP module for python?

(i found pycsp, but i'm not sure i trust the code;
moreover i can't alt on output, or even on a channel
which several processes are writing to, which blows
away some of my most useful idioms...)

i'll probably end up porting the plan 9 code, but
i wanted to check first.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] python csp
  2009-03-11 16:58 [9fans] python csp roger peppe
@ 2009-03-11 17:13 ` gdiaz
  2009-03-11 19:10   ` Uriel
  2009-03-12  8:08   ` roger peppe
  0 siblings, 2 replies; 12+ messages in thread
From: gdiaz @ 2009-03-11 17:13 UTC (permalink / raw)
  To: 9fans

hello

i think somone pointed to this on 9fans days ago:

www.stackless.com

slds.

gabi



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] python csp
  2009-03-11 17:13 ` gdiaz
@ 2009-03-11 19:10   ` Uriel
  2009-03-11 19:34     ` J.R. Mauro
  2009-03-12  8:08   ` roger peppe
  1 sibling, 1 reply; 12+ messages in thread
From: Uriel @ 2009-03-11 19:10 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Stackless is fairly well maintained and uptodate, it is also fairly
close to the Limbo model, and it is used in production in some really
big projects.

Unfortunately it seems unlikely that it will ever make it to python
mainline because Guido doesn't like it rather bizarre reasons ("It
allows recursive programming, which is confusing" or some such is the
last I remember) *sigh*

uriel

On Wed, Mar 11, 2009 at 6:13 PM,  <gdiaz@9grid.es> wrote:
> hello
>
> i think somone pointed to this on 9fans days ago:
>
> www.stackless.com
>
> slds.
>
> gabi
>
>



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] python csp
  2009-03-11 19:10   ` Uriel
@ 2009-03-11 19:34     ` J.R. Mauro
  0 siblings, 0 replies; 12+ messages in thread
From: J.R. Mauro @ 2009-03-11 19:34 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Wed, Mar 11, 2009 at 3:10 PM, Uriel <uriel99@gmail.com> wrote:
> Stackless is fairly well maintained and uptodate, it is also fairly
> close to the Limbo model, and it is used in production in some really
> big projects.
>
> Unfortunately it seems unlikely that it will ever make it to python
> mainline because Guido doesn't like it rather bizarre reasons ("It
> allows recursive programming, which is confusing" or some such is the

God forbid we think outside the box! I don't want anything to do with
that crazy recursion stuff.

> last I remember) *sigh*
>
> uriel
>
> On Wed, Mar 11, 2009 at 6:13 PM,  <gdiaz@9grid.es> wrote:
>> hello
>>
>> i think somone pointed to this on 9fans days ago:
>>
>> www.stackless.com
>>
>> slds.
>>
>> gabi
>>
>>
>
>



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] python csp
  2009-03-11 17:13 ` gdiaz
  2009-03-11 19:10   ` Uriel
@ 2009-03-12  8:08   ` roger peppe
  2009-03-12 15:44     ` John Barham
                       ` (2 more replies)
  1 sibling, 3 replies; 12+ messages in thread
From: roger peppe @ 2009-03-12  8:08 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

2009/3/11  <gdiaz@9grid.es>:
> www.stackless.com

not viable. it doesn't even support alt, as far as i can see.

coming up: another port of the 9 code.
maybe i'm hidebound, but i hate to do concurrent
programming without channels!



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] python csp
  2009-03-12  8:08   ` roger peppe
@ 2009-03-12 15:44     ` John Barham
  2009-03-12 16:10       ` roger peppe
  2009-03-12 15:48     ` andrey mirtchovski
  2009-03-12 17:54     ` Joel C. Salomon
  2 siblings, 1 reply; 12+ messages in thread
From: John Barham @ 2009-03-12 15:44 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> coming up: another port of the 9 code.
> maybe i'm hidebound, but i hate to do concurrent
> programming without channels!

How about using queues (http://docs.python.org/library/queue.html)?
I've used them many times for inter-thread communication.

  John



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] python csp
  2009-03-12  8:08   ` roger peppe
  2009-03-12 15:44     ` John Barham
@ 2009-03-12 15:48     ` andrey mirtchovski
  2009-03-12 17:54     ` Joel C. Salomon
  2 siblings, 0 replies; 12+ messages in thread
From: andrey mirtchovski @ 2009-03-12 15:48 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> coming up: another port of the 9 code.
> maybe i'm hidebound, but i hate to do concurrent
> programming without channels!

me too. sign me up for alpha/beta testing.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] python csp
  2009-03-12 15:44     ` John Barham
@ 2009-03-12 16:10       ` roger peppe
  2009-03-12 16:59         ` John Barham
  0 siblings, 1 reply; 12+ messages in thread
From: roger peppe @ 2009-03-12 16:10 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

2009/3/12 John Barham <jbarham@gmail.com>:
> How about using queues (http://docs.python.org/library/queue.html)?

no alt.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] python csp
  2009-03-12 16:10       ` roger peppe
@ 2009-03-12 16:59         ` John Barham
  2009-03-12 19:51           ` roger peppe
  0 siblings, 1 reply; 12+ messages in thread
From: John Barham @ 2009-03-12 16:59 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

>> How about using queues (http://docs.python.org/library/queue.html)?
>
> no alt.

Couldn't you implement it approximately using
http://docs.python.org/library/queue.html#Queue.Queue.qsize?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] python csp
  2009-03-12  8:08   ` roger peppe
  2009-03-12 15:44     ` John Barham
  2009-03-12 15:48     ` andrey mirtchovski
@ 2009-03-12 17:54     ` Joel C. Salomon
  2009-03-12 18:06       ` David Leimbach
  2 siblings, 1 reply; 12+ messages in thread
From: Joel C. Salomon @ 2009-03-12 17:54 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Thu, Mar 12, 2009 at 4:08 AM, roger peppe <rogpeppe@gmail.com> wrote:
> 2009/3/11  <gdiaz@9grid.es>:
>> www.stackless.com
>
> not viable. it doesn't even support alt, as far as i can see.

It seems to me from
<http://www.stackless.com/wiki/Channels#channel-balance> that
Stackless Python's Channels have alt-like capability built-in, i.e.,
support for multiple readers & writers.

—Joel Salomon



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] python csp
  2009-03-12 17:54     ` Joel C. Salomon
@ 2009-03-12 18:06       ` David Leimbach
  0 siblings, 0 replies; 12+ messages in thread
From: David Leimbach @ 2009-03-12 18:06 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 747 bytes --]

On Thu, Mar 12, 2009 at 10:54 AM, Joel C. Salomon <joelcsalomon@gmail.com>wrote:

> On Thu, Mar 12, 2009 at 4:08 AM, roger peppe <rogpeppe@gmail.com> wrote:
> > 2009/3/11  <gdiaz@9grid.es>:
> >> www.stackless.com
> >
> > not viable. it doesn't even support alt, as far as i can see.
>
> It seems to me from
> <http://www.stackless.com/wiki/Channels#channel-balance> that
> Stackless Python's Channels have alt-like capability built-in, i.e.,
> support for multiple readers & writers.
>
> —Joel Salomon
>

Right but what if you want to alt the Channels, not the tasks waiting to
write to a Channel.  It's not quite the same, and sharing the channel seems
a bit weird, but then I'm not used to Stackless' approach either.

Dave

[-- Attachment #2: Type: text/html, Size: 1351 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] python csp
  2009-03-12 16:59         ` John Barham
@ 2009-03-12 19:51           ` roger peppe
  0 siblings, 0 replies; 12+ messages in thread
From: roger peppe @ 2009-03-12 19:51 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 875 bytes --]

2009/3/12 John Barham <jbarham@gmail.com>:
>>> How about using queues (http://docs.python.org/library/queue.html)?
>>
>> no alt.
>
> Couldn't you implement it approximately using
> http://docs.python.org/library/queue.html#Queue.Queue.qsize?

no. "approximately" in this case would mean "wrong".

for the time being, as i'm limited on time, i'm using pycsp
with a very slim wrapper around it to make its interface
palatable. it'll all be hideously inefficient, but i'm not
too concerned about that currently. i've attached it in case
anyone's interested.

joel: multiple readers and writers isn't the same thing as alt
at all - you need to be able to read from more than
one channel at once. sharing a single channel between
several processes doesn't get you that (although it's
great to have, and the plan9/inferno channel model
supports it)

  rog.

[-- Attachment #2: p9csp.py --]
[-- Type: application/octet-stream, Size: 1213 bytes --]

import pycsp

Channel = pycsp.Channel

def chan(*n):
	'''Create a channel. If an argument is given, it specifies
	the buffer size (default 0, unbuffered)'''
	if len(n) == 0:
		n = 0
	else:
		n = n[0]
	if n > 0:
		c = pycsp.BufferedAny2OneChannel(buffer = pycsp.FifoBuffer(n))
	else:
		c = pycsp.Any2OneChannel();
	return c;

def alt(*cs):
	'''alt(chan....)
	Alt waits until one of the channels becomes ready for reading,
	then returns its read member - it is up to the caller
	to do the read'''
	return pycsp.Alternative(*map(lambda c: c.read, cs)).select();

def altf(*cs):
	'''altf(chan..., fn, chan..., fn, ...)
	Altf waits until one of the channels is ready for reading,
	then reads from it, calls its associated function,
	and returns the result of that call.'''

	as = []
	fs = []
	i = 0
	while i < len(cs):
		j = i
		while isinstance(cs[j], Channel):
			j = j + 1
		if i == j:
			raise 'expected channel(s)'
		f = cs[j]
		k = i
		while k < j:
			as.append(cs[k].read)
			fs.append(f)
			k = k + 1
		i = j + 1
	a = pycsp.Alternative(*as)
	s = a.select()
	i = 0
	while i < len(as):
		if s == as[i]:
			return fs[i](s())
		i = i + 1

def spawn(f, *args, **kwargs):
	pycsp.Process(f, *args, **kwargs).start();

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-03-12 19:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-11 16:58 [9fans] python csp roger peppe
2009-03-11 17:13 ` gdiaz
2009-03-11 19:10   ` Uriel
2009-03-11 19:34     ` J.R. Mauro
2009-03-12  8:08   ` roger peppe
2009-03-12 15:44     ` John Barham
2009-03-12 16:10       ` roger peppe
2009-03-12 16:59         ` John Barham
2009-03-12 19:51           ` roger peppe
2009-03-12 15:48     ` andrey mirtchovski
2009-03-12 17:54     ` Joel C. Salomon
2009-03-12 18:06       ` David Leimbach

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).