Created
June 22, 2020 20:47
-
-
Save nkpro2000sr/b0fdb003fda0b37c8d36aa6ca64a6cd9 to your computer and use it in GitHub Desktop.
To set/change value after timeout using Thread.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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