Hi Arthur,
I always thought of it as possible, but now when I think about it in
detail, then I foresee a problem when
mixing the thread version with greenlets.
The greenlets version use a global scheduler and since threads share a
common address space,
the greenlets scheduler would fail. Mixing greenlets and processes
should be no problem at all though,
since processes have a private address space.
import pycsp.processes as heavy
import pycsp.greenlets as light
import sys, time
@light.process
def source(chan_out):
for i in range(10):
time.sleep(0.1)
chan_out("Hello world (%d)\n" % (i))
light.retire(chan_out)
@light.process
def sink(chan_in):
while True:
sys.stdout.write(chan_in())
@heavy.process
def P():
chan = light.Channel()
light.Parallel(
source(chan.writer()),
sink(chan.reader())
)
heavy.Parallel(P()*2)
As expected, when replacing threads with processes, this is the
result:
$ python mixing.py
Exception in thread Thread-2:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/threading.py", line 522, in __bootstrap_inner
self.run()
File "../pycsp/threads/process.py", line 81, in run
File "mixing.py", line 46, in P
sink(chan.reader())
File "../pycsp/greenlets/process.py", line 184, in Parallel
File "../pycsp/greenlets/process.py", line 207, in _parallel
File "../pycsp/greenlets/scheduling.py", line 267, in join
error: cannot switch to a different thread
One might consider to add a thread_id to global greenlet scheduler.
Best regards, Rune
On Jun 11, 10:15 am, Arthur Edelstein <
arthuredelst...@gmail.com>
wrote: