Feb-05-2020, 01:15 PM
I have a class to handle alerts that, at the end of the process, will be sent in an email. This alerts are list that should be updated during the process execution.
The point is that the process uses different modules (classes) in different files so...
My question is: what is the pythonic way of handling this alerts class?
I think this python pattern (Borg) could help me...
https://github.com/faif/python-patterns/...al/borg.py
But when I import and instantiate the class, lists are empty.
The point is that I don't know if using Singleton in this kind of situation is good idea or not...
Thank you in advance!
The point is that the process uses different modules (classes) in different files so...
My question is: what is the pythonic way of handling this alerts class?
- Declare it at the beginnig of the process and pass it as argument to the different modules handlers?
- Maybe create it as Singleton?
- Any other idea is obviously welcome!
I think this python pattern (Borg) could help me...
https://github.com/faif/python-patterns/...al/borg.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
class Borg: __shared_state = {} def __init__( self ): self .__dict__ = self .__shared_state self .state = 'Init' def __str__( self ): return self .state class MyBorg(Borg): def __init__( self ): Borg.__init__( self ) self .alert_one = [] self .alert_two = [] ... |
The point is that I don't know if using Singleton in this kind of situation is good idea or not...
Thank you in advance!