Skip to content

Instantly share code, notes, and snippets.

@Lucretiel
Last active December 15, 2016 01:39
Show Gist options
  • Save Lucretiel/4c7026ec9831f4203dedd8e38dd3404b to your computer and use it in GitHub Desktop.
Save Lucretiel/4c7026ec9831f4203dedd8e38dd3404b to your computer and use it in GitHub Desktop.
class SyncClientThread:
def __init__(self):
...
self.stop = False
self.nostop_depth = 0
def Stop(self):
self.stop = True
def IsStopped(self):
return self.nostop_depth == 0 and self.stop
def RaiseIfStopped(self):
if self.stopped:
raise StopError
@contextlib.contextmanager
def NoStop(self):
self.nostop_depth += 1
try:
yield
finally:
self.nostop_depth -= 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment