Skip to content

Instantly share code, notes, and snippets.

@okin
Created June 17, 2014 11:40
Show Gist options
  • Save okin/8d72949b8c4f6b15ead7 to your computer and use it in GitHub Desktop.
Save okin/8d72949b8c4f6b15ead7 to your computer and use it in GitHub Desktop.
Code in eigenem Thread ausführen und mit einer Referenz zum Ursprungsthread arbeiten
def updateConfig(clientId):
with self._updateThreadsLock:
if clientId not in self._updateThreads:
command = u'update %s' % clientId
class UpdateThread(threading.Thread):
def __init__(self, opsiPXEConfdBackend, clientId, command):
threading.Thread.__init__(self)
self._opsiPXEConfdBackend = opsiPXEConfdBackend
self._clientId = clientId
self._command = command
self._delay = 3.0
def run(self):
while self._delay > 0:
try:
time.sleep(0.2)
except:
pass
self._delay -= 0.2
with self._opsiPXEConfdBackend._updateThreadsLock:
logger.debug('Updating config...')
# Doing some stuff...
del self._opsiPXEConfdBackend._updateThreads[self._clientId]
def delay(self):
self._delay = 3.0
self._updateThreads[clientId] = UpdateThread(self, clientId, command)
self._updateThreads[clientId].start()
else:
self._updateThreads[clientId].delay()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment