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)

digraph G {
graph [rankdir=TB, ranksep=1]
edge [labelfontsize=8]
node [shape=plaintext]
0[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">  <TR> <TD ROWSPAN="3" COLSPAN="1" BGCOLOR="khaki">Gen</TD> <TD PORT="p_start" BGCOLOR="lightblue">start</TD>
 </TR> <TR> <TD PORT="p_step" BGCOLOR="lightblue">step</TD> </TR>
<TR> <TD PORT="p_stop" BGCOLOR="lightblue">stop</TD> </TR>
 <TR>
<TD PORT="o_out" BGCOLOR="indianred1">out</TD>
</TR> </TABLE>>];
1[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_in" BGCOLOR="springgreen">in</TD>
</TR> <TR> <TD ROWSPAN="1" COLSPAN="1" BGCOLOR="khaki">Unsafe0</TD>  </TR>  <TR>
<TD PORT="o_out" BGCOLOR="indianred1">out</TD>
</TR> </TABLE>>];
2[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_in" BGCOLOR="springgreen">in</TD>
</TR> <TR> <TD ROWSPAN="1" COLSPAN="1" BGCOLOR="khaki">Unsafe1</TD>  </TR>  <TR>
<TD PORT="o_out" BGCOLOR="indianred1">out</TD>
</TR> </TABLE>>];
3[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_in" BGCOLOR="springgreen">in</TD>
</TR> <TR> <TD ROWSPAN="1" COLSPAN="1" BGCOLOR="khaki">Unsafe2</TD>  </TR>  <TR>
<TD PORT="o_out" BGCOLOR="indianred1">out</TD>
</TR> </TABLE>>];
4[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_in" BGCOLOR="springgreen">in</TD>
</TR> <TR> <TD ROWSPAN="1" COLSPAN="1" BGCOLOR="khaki">Unsafe3</TD>  </TR>  <TR>
<TD PORT="o_out" BGCOLOR="indianred1">out</TD>
</TR> </TABLE>>];
5[label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4"> <TR>
<TD PORT="i_in" BGCOLOR="springgreen">in</TD>
</TR> <TR> <TD ROWSPAN="1" COLSPAN="1" BGCOLOR="khaki">ecto_test::Printer</TD> <TD PORT="p_print_type" BGCOLOR="lightblue">print_type</TD>
 </TR>   </TABLE>>];
0->1 [headport="i_in" tailport="o_out"];
1->2 [headport="i_in" tailport="o_out"];
2->3 [headport="i_in" tailport="o_out"];
3->4 [headport="i_in" tailport="o_out"];
4->5 [headport="i_in" tailport="o_out"];
}

No module named PySide.QtCore
***** 1 ***** 0x1d1dc90
***** 2 ***** 0x1d1dc90