[IPython-dev] ipython1 and synchronous printing of stdout

Hans Meine hans_meine at gmx.net
Thu Jul 24 04:44:45 EDT 2008

Am Dienstag, 22. Juli 2008 22:25:45 schrieb Brian Granger:
> 3.  The Observer/Delegate patterns as are typical is Cocoa.  I know
> that Gael is not fund of this, but I do think this pattern is much
> better than plain callbacks, as it give a nice formal structure to
> everything.  Also, I agree with Barry that this pattern is pretty much
> what you get when you try to do plain callbacks properly.
> Thus, my own conclusion is that the Observer/Delegate pattern is
> probably the best option for us and will lead to the loose coupling
> that we need.
> Barry, what would it take to put together an example of this pattern?
> Will we need some amount of infrastructure to make this possible?

My experience is that a callback mechanism is easily implemented in Python as 
a (standard python) list of callables that are called in turn.  Optionally, 
you may allow to specify priorities when adding callbacks to get the proper 
order, but that looks like overkill here.  This relies on Python's automatic 
member function binding and duck typing (i.e. you can pass objects with a 
__call__ method, normal functions, or bound member functions) and works very 

AFAICS, there is no big difference between supporting callbacks and the 
Observer pattern; if you provide an "addOutputCallback" method that 
internally appends its argument to a list of outputCallbacks, an Observer 
would simply call that method and pass self (if it has a specific __call__ 
method) or e.g. self._watchOutput.  The latter IMHO makes it so powerful 
because an Observer may easily watch several different Subjects without being 
forced to follow a certain interface (i.e. method names) for that.

Just my 2 cents,

PS: Forgot to press send; I actually wrote this about 24 hours ago.  Looks 
nearly off-topic to me now, but anyhow..

More information about the IPython-dev mailing list