Specify def thloop( th ): while th.cont: with th.step[2]: th.ret= th.cmd+ 1 def acq( th ): with th.step[1]: th.cmd= 100 with th.step[3]: ret1= th.ret th.step.reset() assert ret1== 101 Is it enough?