Skip to content

Commit

Permalink
Ensure SelectConsumerThread has an available asynctio event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed Jan 16, 2025
1 parent 758698e commit 96b1c88
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions neon_mq_connector/consumers/select_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


import threading
import time

from asyncio import Event
from asyncio import Event, get_event_loop, set_event_loop, new_event_loop
from typing import Optional

import pika.exceptions
Expand Down Expand Up @@ -205,6 +203,12 @@ def is_consuming(self) -> bool:

def run(self):
"""Starting connection io loop """
try:
if get_event_loop() is None:
set_event_loop(new_event_loop())
except RuntimeError:
set_event_loop(new_event_loop())

if not self.is_consuming:
try:
self.connection: pika.SelectConnection = self.create_connection()
Expand Down

0 comments on commit 96b1c88

Please sign in to comment.