import queue
import threading


def loop(queue, actor):
    while True:
        message = queue.get()
        actor.behavior(message)

        
class Actor(object):

    def __init__(self):
        pass
        
    def _start_loop(self):
        self.queue = queue.Queue()
        self.dispatcher = threading.Thread(
            target=loop,
            args=(self.queue, self))
        self.dispatcher.start()
        
    def __call__(self, message):
        self.queue.put(message)

    @classmethod
    def create(cls, *args):
        actor = cls(*args)
        actor._start_loop()
        return actor

@@ -29,16 +29,26 @@
 g%0A%0A%0Adef 
+indiviual_
 loop(que
@@ -142,80 +142,162 @@
 e)%0A%0A
-        %0Aclass Actor(object):%0A%0A    def __init__(self):%0A        pass%0A    
+%0Adef global_loop(queue):%0A    while True:%0A        actor, message = queue.get()%0A        actor.behavior(message)%0A%0A%0Aclass EventLoop(object):%0A%0A    loop = None%0A
     
@@ -306,26 +306,23 @@
    def _
-start_loop
+_init__
 (self):%0A
@@ -369,26 +369,22 @@
    self.
-dispatcher
+thread
  = threa
@@ -415,16 +415,23 @@
  target=
+global_
 loop,%0A  
@@ -461,240 +461,1338 @@
 eue,
- self))%0A        self.dispatcher.start()%0A        %0A    def __call__(self, message):%0A        self.queue.put(message)%0A%0A    @classmethod%0A    def create(cls, *args):%0A        actor = cls(*args)%0A        actor._start_loop()%0A        return actor
+),%0A            name='global-loop')%0A        self.thread.start()%0A%0A    def schedule(self, message, target):%0A        self.queue.put((target, message))%0A        %0A    @classmethod%0A    def get_loop(cls):%0A        if cls.loop is None:%0A            cls.loop = cls()%0A        return cls.loop%0A                    %0A%0Aclass AbstractActor(object):%0A%0A    def __call__(self, message):%0A        self._put(message)%0A%0A    def _put(self, message):%0A        raise NotImplementedError()%0A%0A    def _ensure_loop(self):%0A        pass%0A        %0A    @classmethod%0A    def create(cls, *args):%0A        actor = cls(*args)%0A        actor._ensure_loop()%0A        return actor%0A%0A%0Aclass ActorOwnLoop(AbstractActor):%0A%0A    def _put(self, message):%0A        self.queue.put(message)%0A        %0A    def _ensure_loop(self):%0A        self.queue = queue.Queue()%0A        self.dispatcher = threading.Thread(%0A            target=indiviual_loop,%0A            args=(self.queue, self),%0A            name=self._thread_name())%0A        self.dispatcher.start()%0A%0A    def _thread_name(self):%0A        return '%7B%7D-%7B%7D'.format(%0A            self.__class__.__name__,%0A            hex(id(self)))%0A        %0A        %0Aclass ActorGlobalLoop(AbstractActor):%0A%0A    def _put(self, message):%0A        self.loop.schedule(message, self)%0A%0A    def _ensure_loop(self):%0A        self.loop = EventLoop.get_loop()%0A%0A%0AActor = ActorGlobalLoop
 %0A

Refactor to allow different event loops