Pika with Python select? #1459
-
Hi all, I'd like to know if it is possible to use pika directly with the python select module. I have a project on Linux that uses select to coordinate multiple socket and serial connections and I am interested in adding AMQP messaging to it. select() is mentioned in the Introduction of the pika README, but I can't seem to find any further information on how that might work in the docs here or elsewhere on the web. The current application uses an MQTT library that directly exposes the socket connection to add to select, along with functions for manual loop control. Is there anything similar in pika, or is integrating with select possible at all? I'd greatly appreciate any help in finding some examples or source code that I may have missed while searching, or suggestions for alternatives you may have. Thanks! Evan |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
https://github.com/pika/pika/blob/main/pika/adapters/select_connection.py It looks like there are methods to add file descriptors to the set that Otherwise, I would suggest running your AMQP connections in their own thread, and leaving Pika to manage it. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick reply, have been working on this today and had some success adding the other file descriptors into the pika ioloop. Basically, before calling |
Beta Was this translation helpful? Give feedback.
Thanks for the quick reply, have been working on this today and had some success adding the other file descriptors into the pika ioloop. Basically, before calling
.ioloop.start()
on the connection you can use.ioloop.add_handler(fd, handler, events)
, (line 513 in file linked above) getting fd from the socket/serial connection.fileno()
method and adding a handler callback that accepts the fileno and event type as args. Works well enough, much appreciated Luke!