Python Forum
Pythonic way to handle/spread alerts class in multiple modules
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pythonic way to handle/spread alerts class in multiple modules
#1
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?
  • 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

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 = []
        ...
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!
Reply


Messages In This Thread
Pythonic way to handle/spread alerts class in multiple modules - by psolar - Feb-05-2020, 01:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to handle multiple audio uploads without canceling ongoing API requests? muba 2 1,201 Jan-01-2025, 01:04 AM
Last Post: Skaperen
  Can I use logging in a class (without multiple messages) mevan 2 1,423 Oct-16-2023, 11:08 PM
Last Post: mevan
  Pythonic from a C++ perspective PyDan 2 1,550 Sep-18-2023, 11:39 AM
Last Post: PyDan
  What's the best way for multiple modules to handle database activity? SuchUmami 3 1,634 Jul-08-2023, 05:52 PM
Last Post: deanhystad
  How to append multiple <class 'str'> into a single List ahmedwaqas92 2 3,195 Jan-07-2021, 08:17 AM
Last Post: ahmedwaqas92
  Is this use of exec pythonic? psolar 1 2,476 Feb-07-2020, 12:23 PM
Last Post: buran
  which is "better" (or more Pythonic)? Skaperen 2 2,954 Feb-01-2020, 03:10 PM
Last Post: Skaperen
  which is "better" (or more Pythonic)? Skaperen 7 4,767 Feb-01-2020, 03:51 AM
Last Post: Skaperen
  which is "better" (or more Pythonic)? Skaperen 8 5,148 Nov-16-2019, 06:46 PM
Last Post: Skaperen
  which is more Pythonic? Skaperen 5 4,181 Jul-16-2019, 01:00 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020