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
#1
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):

main.py
---------
def producer(q_in):
    producerObj = MySlackAPIObj(q_in)
    pool.apply_async(producerObj.run())

if __name__ == '__main__':
    pool = mp.Pool()
    manager = mp.Manager()
    dataQueue = manager.Queue()
    producer(dataQueue)
    ..
slackapi.py
-------------
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
    @slack_events_adapter.on("message")
    def handle_message(event_data):
        message = event_data["event"]
        self.theQueue.put( message )           #  This is where it errors!   Self not defined

    # Error events
    @slack_events_adapter.on("error")
    def error_handler(err):
        print("ERROR: " + str(err))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  error in class: TypeError: 'str' object is not callable akbarza 2 445 Dec-30-2023, 04:35 PM
Last Post: deanhystad
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 989 Sep-19-2022, 02:32 AM
Last Post: Xeno
  Multiprocessing queue catch get timeout Pythocodras 1 2,240 Apr-22-2022, 06:01 PM
Last Post: Pythocodras
  Class variables and Multiprocessing(or concurrent.futures.ProcessPoolExecutor) Tomli 5 3,779 Nov-12-2021, 09:55 PM
Last Post: snippsat
  Multiprocessing Can't pickle local object law 1 15,713 Aug-30-2021, 02:49 PM
Last Post: law
Exclamation win32com: How to pass a reference object into a COM server class Alfalfa 3 4,801 Jul-26-2021, 06:25 PM
Last Post: Alfalfa
  AttributeError class object has no attribute list object scttfnch 5 3,343 Feb-24-2021, 10:03 PM
Last Post: scttfnch
  multiprocessing and sharing object cyrduf 0 2,011 Feb-02-2021, 08:16 PM
Last Post: cyrduf
  Python Class and Object Parameters JoeDainton123 5 2,828 Sep-02-2020, 10:43 AM
Last Post: JoeDainton123
  task queue Valon1981 8 3,517 Jul-07-2020, 07:41 AM
Last Post: freeman

Forum Jump:

User Panel Messages

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