Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

EventListener.py 605 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  1. from collections import Iterable
  2. class EventListener:
  3. __slots__ = ['_funcs']
  4. def __init__(self):
  5. self._funcs = []
  6. def has_listeners(self):
  7. return len(self._funcs) != 0
  8. def add(self, func_or_list):
  9. if isinstance(func_or_list, Iterable):
  10. func_or_list = tuple(func_or_list)
  11. else:
  12. func_or_list = (func_or_list,)
  13. for func in func_or_list:
  14. if func not in self._funcs:
  15. self._funcs.append(func)
  16. def call(self, *args, **kwargs):
  17. for func in self._funcs:
  18. func(*args, **kwargs)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...