def test_enter_exit(self): reporter1 = chainer.Reporter() reporter2 = chainer.Reporter() with reporter1: self.assertIs(chainer.get_current_reporter(), reporter1) with reporter2: self.assertIs(chainer.get_current_reporter(), reporter2) self.assertIs(chainer.get_current_reporter(), reporter1)
def test_scope(self): reporter1 = chainer.Reporter() reporter2 = chainer.Reporter() with reporter1: observation = {} with reporter2.scope(observation): self.assertIs(chainer.get_current_reporter(), reporter2) self.assertIs(reporter2.observation, observation) self.assertIs(chainer.get_current_reporter(), reporter1) self.assertIsNot(reporter2.observation, observation)
def thread_func(reporter, record): with reporter: # Sleep for a tiny moment to cause an overlap of the context # managers. time.sleep(0.01) record.append(chainer.get_current_reporter())