# Path: servicebus/utils.py
# def _do_close_sockets():
# def close_sockets():
# def num_sockets():


import sys
import time
import copy
import signal
import logging
import asyncore
from threading import Thread
from multiprocessing import Process
from servicebus import utils
    from Queue import Queue
    from queue import Queue
            msg_type, params = self.queue.get()
            if msg_type == "stop":
                self.queue.task_done()
                break
            # We copy the service object is for each message process.
            # This copy is for Background Service running. If we do not
            # copy this object, Background Service will return last received
            # message's data. So if there has 2 same service running in background
            # will cause a status report bug.
            service = copy.copy(self.service)
            if self.is_background:
                logging.info("Run in background")
                thread = Thread(target=self.run_service, args=(service, msg_type, params))
                thread.start()
                self.add_background_service(thread)
            else:
                self.run_service(service, msg_type, params)
            self.queue.task_done()
        self.wait_background_services()

    def run_service(self, service, msg_type, params):
        try:
            if msg_type == "message":
                service.on_message(*params)
            elif msg_type == "call":
                service.on_call(*params)
        except Exception as e:
            logging.exception(e)

        if len(params) > 0:

# Path: servicebus/utils.py
# def _do_close_sockets():
# def close_sockets():
# def num_sockets():


# Path: servicebus/service.py
import sys
import time
import copy
import signal
import logging
import asyncore
from threading import Thread
from multiprocessing import Process
from servicebus import utils
    from Queue import Queue
    from queue import Queue

            msg_type, params = self.queue.get()
            if msg_type == "stop":
                self.queue.task_done()
                break
            # We copy the service object is for each message process.
            # This copy is for Background Service running. If we do not
            # copy this object, Background Service will return last received
            # message's data. So if there has 2 same service running in background
            # will cause a status report bug.
            service = copy.copy(self.service)
            if self.is_background:
                logging.info("Run in background")
                thread = Thread(target=self.run_service, args=(service, msg_type, params))
                thread.start()
                self.add_background_service(thread)
            else:
                self.run_service(service, msg_type, params)
            self.queue.task_done()
        self.wait_background_services()

    def run_service(self, service, msg_type, params):
        try:
            if msg_type == "message":
                service.on_message(*params)
            elif msg_type == "call":
                service.on_call(*params)
        except Exception as e:
            logging.exception(e)

        if len(params) > 0:

            request = params[0]