Communicating to pycsp.greenlets.Processes from the main thread?

5 views
Skip to first unread message

Dirk Hasselbalch

unread,
Jun 14, 2010, 11:16:48 AM6/14/10
to py...@googlegroups.com
Hi Rune et al,

How do I communicate from my main thread to a pycsp.greenlets.Process instance?

This fails:

>>> import pycsp.greenlets as pycsp
>>> @pycsp.process
... def func(cout):
... while True:
... cout(42)
...
>>> ch = pycsp.Channel()
>>> cin, cout = +ch, -ch
>>> pycsp.Spawn(func(cout))
>>> answer = cin()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/pycsp/greenlets/channel.py",
line 111, in _read
p.setstate(ACTIVE)
AttributeError: 'NoneType' object has no attribute 'setstate'
>>>

since the main thread is not a greenlet (I assume based on about 2
mins of debugging ;). There is of course no problems with neither
pycsp.threads nor pycsp.processes.

How would one do this? Do I need to create a wrapping
pycsp.processes.Process around two greenlets, and let one of them
communicate back to the main process through a processes.Channel
(probably wrapped in an @io)? (I take it, from Arthurs mail earlier,
that this trick would probably not work for threads.)

But maybe there is a smarter (more lightweight) solution?

Regards
Dirk

Rune M. Friborg

unread,
Jun 25, 2010, 10:03:44 AM6/25/10
to pycsp
Hi,

This is definitely a very annoying defect of the greenlet
implementation.

I committed a fix 5 minutes ago. :-)

So you should be able to download the latest revision
from trunk and run your app again.

> But maybe there is a smarter (more lightweight) solution?

You've done it correctly and I don't see any other nice way to do it.


Best Regards, Rune
Reply all
Reply to author
Forward
0 new messages