global interpreter lock

Michael Sparks ms at
Thu Sep 15 21:50:03 CEST 2005

Michele Simionato wrote:

> It looks like I am reinventing Twisted and/or Kamaelia.

If it's /fun/ , is that a problem ? ;) (Interesting implementation BTW :)

FWIW, I've about a year ago it wasn't clear if we would be able to release
our stuff, so as part of a presentation I included a minimalistic decorator
based version of our system that has some similarities to yours. (The idea
was then at least the ideas had been shared, if not the main code - which
had approval)

Posted below in case it's of interest:

import copy
def wrapgenerator(bases=object, **attrs):
   def decorate(func):
       class statefulgenerator(bases):
          __doc__ = func.__doc__
          def __init__(self,*args):
           super(statefulgenerator, self) __init__(*args)
           for k in attrs.keys():
             self.__dict__[k] = copy.deepcopy(attrs[k])
          def __iter__(self): return iter(self.func)
       return statefulgenerator
   return decorate

class com(object):
  def __init__(_, *args):
     # Default queues
     _.queues = {"inbox":[],"control":[],
                 "outbox":[], "signal":[]}
  def send(_,box,obj): _.queues[box].append(obj)
  def dataReady(_,box): return len(_.queues[box])>0
  def recv(_, box): # NB. Exceptions aren't caught
    del _.queues[box][0]
    return X

A sample component written using this approach then looks like this:

def forwarder(self):
   "Simple data forwarding generator"
   while 1:
      if self.dataReady("inbox"):
      elif self.dataReady("control"):
         if self.recv("control") == "shutdown":
      yield 1
   yield 0

Since we're not actualy using this approach, there's likely to be border
issues here. I'm not actually sure I like this particular approach, but it
was an interesting experiment.

Best Regards,


More information about the Python-list mailing list