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