[IPython-dev] check for "q" or abort in a custom magic-function

Alexander Krause admin at erazor-zone.de
Wed Jun 20 10:44:27 EDT 2012

Hi all,

I started to play a bit with iPython today and decided to add some
functions for general automation purposes.

I already implemented a pure ModBus master/slave in python and added
wrote a custom class for a ModBus device.

With iPython it's pretty nice to manipulate and program such devices.
I overloaded the __getattr__ and __setattr__ and am able to read the
value of a device by just typing:
In [3]: AC.OnOff
Out[3]: 0

Or write the value via:
In [4]: AC.OnOff=1

Another nice feature would be to actually monitor the value of a object.

For this purpose I started to write a magic function which more or less
does the same like the linux command watch:
<code python>

def magic_watch(self,cmd):
	import time
	while True:


Is there a way to actually call self.ev? I suppose I've to flush some
stdout buffers to get the output?

How can I check for example for the key q to abort the loop?

Thanks a lot for any hints!


More information about the IPython-dev mailing list