Python Forum
Multiprocessing, class, run and a Queue Object
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiprocessing, class, run and a Queue Object
Using multiprocessing and having difficulty understanding the syntax to use within a class. The premise is that there is a producer process who listens for web requests via a Flask instantiation (attaching to and using Slack API), puts them on a shared Queue object, and then consumers read and process the elements in the queue. I am having issues with the producer. I can't figure how to get access to the "Queue" when a message comes in. I can't seem to override the handle_message as it comes from the Slack Events API. Is there another way/better way to do this?

(Abbreviated to get the main jist):
def producer(q_in):
    producerObj = MySlackAPIObj(q_in)

if __name__ == '__main__':
    pool = mp.Pool()
    manager = mp.Manager()
    dataQueue = manager.Queue()
class MySlackAPIObj:
    def __init__(self, q):
        self.theQueue = q

    def run(self):
        slack_events_adapter.start(port=3000, debug=True, use_reloader=False)

    # Example responder to messages posted
    def handle_message(event_data):
        message = event_data["event"]
        self.theQueue.put( message )           #  This is where it errors!   Self not defined

    # Error events
    def error_handler(err):
        print("ERROR: " + str(err))

Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError class object has no attribute list object scttfnch 5 378 Feb-24-2021, 10:03 PM
Last Post: scttfnch
  multiprocessing and sharing object cyrduf 0 218 Feb-02-2021, 08:16 PM
Last Post: cyrduf
  Python Class and Object Parameters JoeDainton123 5 948 Sep-02-2020, 10:43 AM
Last Post: JoeDainton123
  task queue Valon1981 8 1,237 Jul-07-2020, 07:41 AM
Last Post: freeman
  Hi, need help with class, object Houston222 1 488 Apr-04-2020, 01:55 PM
Last Post: buran
  Queue in Pygame constantin01 1 1,128 Jan-07-2020, 04:02 PM
Last Post: metulburr
  Queue maxsize mr_byte31 2 1,526 Sep-03-2019, 07:02 PM
Last Post: mr_byte31
  class returns NoneType Object istemihan 0 864 Aug-12-2019, 11:47 AM
Last Post: istemihan
  Multiprocessing.Queue Issues (Missing/Corrupted Items/No Output) python3noob 0 887 Aug-03-2019, 09:38 PM
Last Post: python3noob
  multiprocessing.Queue.put(,,0) not documented Skaperen 2 617 Jul-30-2019, 09:01 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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