Jul-12-2020, 05:36 PM
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
---------
-------------
(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))
