Skip to content

Instantly share code, notes, and snippets.

@nkpro2000sr
Created June 22, 2020 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkpro2000sr/b0fdb003fda0b37c8d36aa6ca64a6cd9 to your computer and use it in GitHub Desktop.
Save nkpro2000sr/b0fdb003fda0b37c8d36aa6ca64a6cd9 to your computer and use it in GitHub Desktop.
To set/change value after timeout using Thread.
class _Setattr_after_timeout(threading.Timer):
""" To set values after timeout to attribute of a object """
def __init__(self, timeout, obj, **attrsAvalue):
"""
Args:
timeout (int):
Time (in seconds) after which value should be set to attribute of obj.
obj (object):
Object whose attributes have to set
**attrsAvalue :
Mapping of attribute to value
"""
super().__init__(timeout, self._todo)
self.obj = obj
self.attrsAvalue = attrsAvalue
def _todo(self):
for attr, value in self.attrsAvalue.items():
setattr(self.obj, attr, value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment