# Path: pyactor/thread/actor.py
# class Actor(ActorRef):
#     """
#     Actor is the instance of an object to which is possible to access
#     and invoke its methods remotely. Main element of the model. The
#     host is the one to create them (spawning -> see :meth:`~.spawn`).
# 
#     :param str. url: URL where the actor is running.
#     :param class klass: class type for the actor.
#     :param klass obj: instance of the *klass* class to attach to the
#         actor.
#     """
# 
#     def __init__(self, url, klass, obj):
#         super(Actor, self).__init__(url, klass)
#         self._obj = obj
#         self.id = obj.id
#         self.running = True
#         self.thread = None
#         self.future_manager = FutureManager()
# 
#     def __process_queue(self):
#         while self.running:
#             message = self.channel.receive()
#             self.receive(message)
# 
#     def is_alive(self):
#         """
#         :return: (*bool.*) identifies the current state of the actor.
#             **True** if it is running.
#         """
#         return self.running
# 
#     def receive(self, msg):
#         """
#         The message received from the queue specifies a method of the
#         class the actor represents. This invokes it. If the
#         communication is an ASK, sends the result back
#         to the channel included in the message as an ASK_RESPONSE.
# 
#         If it is a FUTURE, generates a FUTURE_RESPONSE
#         to send the result to the manager.
# 
#         :param msg: The message is a dictionary using the constants
#             defined in util.py (:mod:`pyactor.util`).
#         """
#         if msg[TYPE] == TELL and msg[METHOD] == 'stop':
#             self.running = False
#             self.future_manager.stop()
#         else:
#             try:
#                 invoke = getattr(self._obj, msg[METHOD])
#                 params = msg[PARAMS]
#                 result = invoke(*params[0], **params[1])
#             except Exception as e:
#                 if msg[TYPE] == TELL:
#                     print(e)
#                     return
#                 result = e
#             self.send_response(result, msg)
# 
#     def send_response(self, result, msg):
#         if msg[TYPE] == ASK:
#             response = {TYPE: ASK_RESPONSE, RESULT: result,
#                         RPC_ID: msg[RPC_ID] if RPC_ID in msg.keys() else None}
#             msg[CHANNEL].send(response)
#         elif msg[TYPE] == FUTURE:
#             response = {TYPE: FUTURE_RESPONSE, RPC_ID: msg[RPC_ID],
#                         RESULT: result}
#             msg[CHANNEL].send(response)
# 
#     def run(self):
#         """
#         Creates the actor thread which will process the channel queue
#         while the actor :meth:`is_alive`, making it able to receive
#         queries.
#         """
#         self.thread = Thread(target=self.__process_queue)
#         self.thread.start()
# 
# Path: pyactor/util.py
# def get_host():
#     if core_type == 'thread':
#         current = current_thread()
#     else:
#         current = getcurrent()
#     for host in hosts.values():
#         if current in host.threads.keys():
#             return host
#         elif current in host.pthreads.keys():
#             return host
#     return main_host
# 
# METHOD = 'METHOD'
# 
# PARAMS = 'PARAMS'
# 
# TYPE = 'TYPE'
# 
# TELL = 'TELL'


import uuid
from threading import Lock, current_thread
from time import sleep
from .actor import Actor
from ..util import get_host, METHOD, PARAMS, TYPE, TELL
        super(ActorParallel, self).__init__(url, klass, obj)
        self.__lock = Lock()
        self.pending = {}
        self.ask_parallel = (self.ask | self.ask_ref) & klass._parallel
        self.tell_parallel = (self.tell | self.tell_ref) & klass._parallel

        for method in self.ask_parallel:
            setattr(self._obj, method,
                    ParallelAskWrapper(getattr(self._obj, method), self,
                                       self.__lock))
        for method in self.tell_parallel:
            setattr(self._obj, method,
                    ParallelTellWrapper(getattr(self._obj, method), self,
                                        self.__lock))

    def receive(self, msg):
        """
        Overwriting :meth:`Actor.receive`. Adds the checks and
        features required by parallel methods.

        :param msg: The message is a dictionary using the constants
            defined in util.py (:mod:`pyactor.util`).
        """
        if msg[TYPE] == TELL and msg[METHOD] == 'stop':
            self.running = False
        else:
            try:
                invoke = getattr(self._obj, msg[METHOD])
                params = msg[PARAMS]


# Path: pyactor/thread/actor.py
# class Actor(ActorRef):
#     """
#     Actor is the instance of an object to which is possible to access
#     and invoke its methods remotely. Main element of the model. The
#     host is the one to create them (spawning -> see :meth:`~.spawn`).
# 
#     :param str. url: URL where the actor is running.
#     :param class klass: class type for the actor.
#     :param klass obj: instance of the *klass* class to attach to the
#         actor.
#     """
# 
#     def __init__(self, url, klass, obj):
#         super(Actor, self).__init__(url, klass)
#         self._obj = obj
#         self.id = obj.id
#         self.running = True
#         self.thread = None
#         self.future_manager = FutureManager()
# 
#     def __process_queue(self):
#         while self.running:
#             message = self.channel.receive()
#             self.receive(message)
# 
#     def is_alive(self):
#         """
#         :return: (*bool.*) identifies the current state of the actor.
#             **True** if it is running.
#         """
#         return self.running
# 
#     def receive(self, msg):
#         """
#         The message received from the queue specifies a method of the
#         class the actor represents. This invokes it. If the
#         communication is an ASK, sends the result back
#         to the channel included in the message as an ASK_RESPONSE.
# 
#         If it is a FUTURE, generates a FUTURE_RESPONSE
#         to send the result to the manager.
# 
#         :param msg: The message is a dictionary using the constants
#             defined in util.py (:mod:`pyactor.util`).
#         """
#         if msg[TYPE] == TELL and msg[METHOD] == 'stop':
#             self.running = False
#             self.future_manager.stop()
#         else:
#             try:
#                 invoke = getattr(self._obj, msg[METHOD])
#                 params = msg[PARAMS]
#                 result = invoke(*params[0], **params[1])
#             except Exception as e:
#                 if msg[TYPE] == TELL:
#                     print(e)
#                     return
#                 result = e
#             self.send_response(result, msg)
# 
#     def send_response(self, result, msg):
#         if msg[TYPE] == ASK:
#             response = {TYPE: ASK_RESPONSE, RESULT: result,
#                         RPC_ID: msg[RPC_ID] if RPC_ID in msg.keys() else None}
#             msg[CHANNEL].send(response)
#         elif msg[TYPE] == FUTURE:
#             response = {TYPE: FUTURE_RESPONSE, RPC_ID: msg[RPC_ID],
#                         RESULT: result}
#             msg[CHANNEL].send(response)
# 
#     def run(self):
#         """
#         Creates the actor thread which will process the channel queue
#         while the actor :meth:`is_alive`, making it able to receive
#         queries.
#         """
#         self.thread = Thread(target=self.__process_queue)
#         self.thread.start()
# 
# Path: pyactor/util.py
# def get_host():
#     if core_type == 'thread':
#         current = current_thread()
#     else:
#         current = getcurrent()
#     for host in hosts.values():
#         if current in host.threads.keys():
#             return host
#         elif current in host.pthreads.keys():
#             return host
#     return main_host
# 
# METHOD = 'METHOD'
# 
# PARAMS = 'PARAMS'
# 
# TYPE = 'TYPE'
# 
# TELL = 'TELL'


# Path: pyactor/thread/parallels.py
import uuid
from threading import Lock, current_thread
from time import sleep
from .actor import Actor
from ..util import get_host, METHOD, PARAMS, TYPE, TELL

        super(ActorParallel, self).__init__(url, klass, obj)
        self.__lock = Lock()
        self.pending = {}
        self.ask_parallel = (self.ask | self.ask_ref) & klass._parallel
        self.tell_parallel = (self.tell | self.tell_ref) & klass._parallel

        for method in self.ask_parallel:
            setattr(self._obj, method,
                    ParallelAskWrapper(getattr(self._obj, method), self,
                                       self.__lock))
        for method in self.tell_parallel:
            setattr(self._obj, method,
                    ParallelTellWrapper(getattr(self._obj, method), self,
                                        self.__lock))

    def receive(self, msg):
        """
        Overwriting :meth:`Actor.receive`. Adds the checks and
        features required by parallel methods.

        :param msg: The message is a dictionary using the constants
            defined in util.py (:mod:`pyactor.util`).
        """
        if msg[TYPE] == TELL and msg[METHOD] == 'stop':
            self.running = False
        else:
            try:
                invoke = getattr(self._obj, msg[METHOD])
                params = msg[PARAMS]


                if msg[METHOD] in self.ask_parallel: