How to do Nonblocking writes of unhashable data: Alternation([{ (c, unhashable): None }])

4 views
Skip to first unread message

Peter Waller

unread,
Oct 1, 2010, 8:10:12 AM10/1/10
to pycsp, j...@cs.uit.no
How do I use an alternation with unhashable data, such as a
dictionary?

I wrote the following function, but it doesn't work if `what` is
unhashable. Is there another obvious way to achieve what I want?

def nonblock_write(comm_channel, what):
"""
Tries to write `what` to `comm_channel`.
returns True on successful write
"""
chan, msg = P.Alternation([
{ (comm_channel, what): None },
{ P.Skip(): None },
]).execute()

return chan == comm_channel

TIA.
- Peter

Peter Waller

unread,
Oct 1, 2010, 8:25:41 AM10/1/10
to pycsp, j...@cs.uit.no
A quick read of the pycsp code made it obvious that one can also do:

   chan, msg = P.Alternation([
       (comm_channel, what, None),
       { P.Skip(): None },
   ]).execute()

Which is functionally equivalent but doesn't have this limitation.

Thanks anyway.

Rune Møllegaard Friborg

unread,
Oct 1, 2010, 8:26:14 AM10/1/10
to py...@googlegroups.com
This is a problem with the original syntax.

The new syntax:
chan, msg = P.AltSelect(P.OutputGuard(comm_channel, msg=what), P.SkipGuard())

Look at the examples in trunk for inspiraition.


Mvh.
Rune M. Friborg

Peter Waller

unread,
Oct 1, 2010, 8:34:23 AM10/1/10
to py...@googlegroups.com
2010/10/1 Rune Møllegaard Friborg <ru...@diku.dk>

This is a problem with the original syntax.

The new syntax:
chan, msg = P.AltSelect(P.OutputGuard(comm_channel, msg=what), P.SkipGuard())

Look at the examples in trunk for inspiraition.

Oh, I thought I was looking at the new syntax - I was going by the "PyCSP Revisited" document.
Reply all
Reply to author
Forward
0 new messages