Strands: preventing cells from running concurrentlyΒΆ
Strands are used by the schedulers when cells must not run
concurrently with specific instances or other cells. Simply create a
strand and pass it as the argument strand
when creating cells: no
cells that have the same strand will ever run at the same time.
One can also mark all instances of the same type of cell as always thread-unsafe, see ECTO_THREAD_UNSAFE().
Sample:
#!/usr/bin/env python
import ecto
import ecto.ecto_test as ecto_test
s1 = ecto.Strand() # No cells that have this strand will run concurrenly
plasm = ecto.Plasm()
gen = ecto_test.Generate("Gen", step=1.0, start=1.0)
noncurr = ecto_test.DontCallMeFromTwoThreads("Unsafe0", strand=s1)
plasm.connect(gen['out'] >> noncurr['in'])
for k in range(3):
next = ecto_test.DontCallMeFromTwoThreads("Unsafe%u" % (k+1), strand=s1)
plasm.connect(noncurr['out'] >> next['in'])
noncurr = next
printer = ecto_test.Printer()
plasm.connect(noncurr['out'] >> printer['in'])
if __name__ == '__main__':
sched = ecto.Scheduler(plasm)
sched.execute(niter=2)
No module named PySide.QtCore
***** 1 ***** 0x1d1dc90
***** 2 ***** 0x1d1dc90