You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

hook.py 420 B

12345678910111213141516
  1. import weakref
  2. class HookHandler:
  3. hook_num = 0
  4. def __init__(self, source_dict, hook):
  5. self.id = HookHandler.hook_num
  6. HookHandler.hook_num += 1
  7. source_dict[self.id] = hook
  8. self.source_ref = weakref.ref(source_dict)
  9. def remove(self):
  10. source_dict = self.source_ref()
  11. if source_dict is not None and self.id in source_dict:
  12. del source_dict[self.id]