Issues stopping and starting service runners programmatically

Describe the bug
I am building services for our microservices to speak to one another. I am trying to spike a service for stopping services programmatically based on the availability of other online services. So I put together a script that has a loop which I am trying to start and stop service runners. The script runs and the service seems to start and I can receive messages from my sending service then it stops, as it should, but then the service does not seem to start up again.

To Reproduce
Below is my code for the receiving service:

from import EventDispatcher, event_handler
from nameko.rpc import rpc
from nameko.runners import ServiceRunner
from nameko.testing.utils import get_container
import numpy
import time
import os
import sys
import io

import eventlet

AMQP_URI = 'pyamqp://guest:guest@broker'

config = {
    'AMQP_URI': AMQP_URI,  # e.g. "pyamqp://guest:guest@localhost"
    'serializer': 'pickle'

class ServiceB:

    name = 'event_listen'

    @event_handler("event_dispatch", "reading_queued")
    def handle_Event(self, payload):
        print("service b received this reading: ", str(payload).upper())

    @event_handler('event_dispatch', 'img_receive')
    def handle_img(self, payload):
        for key, value in payload.items():
            with open(f'sent/{key}', 'wb') as img:
        print('Image has been wirtten')

runner = ServiceRunner(config)

container_b = get_container(runner, ServiceB)

if __name__ == '__main__':
        print('Listener Service started: Waiting for messages')
        while True:
            print('Restarting Service')
            print('Stopping Service')
    except KeyboardInterrupt:
        print('Close Out program')
        except SystemExit:

Expected behavior
I was expecting the loop to start the service, print all the waiting queued messages, stop, and then wait for twenty seconds to start again.

Environment (please complete the following information):

  • Nameko version: 2.12
  • Python version: 3.7.9
  • OS: Debian based docker image

Additional context
Created a docker compose based network with a container for the sender service, receiver service, and a rabbitmq container.