[IPython-user] Need post_runcode_hook
Gustavo Carneiro
gjcarneiro@gmail....
Sat Sep 27 10:22:31 CDT 2008
Hello, I think I need a post_runcode_hook in interactive python module
'iplib'.
My use case is the following. I have a real time visualizer for a
simulation system, but I would like to allow IPython commands while the
simulator is running. The simulator runs in a different thread. I would
like to automatically acquire the lock protecting the simulator system
around IPython commands, or else the user may forget to pause the simulation
first and may cause threading problems (the simulator is not
multi-threaded).
I see the new IPython 0.9 has a pre_runcode_hook.
def runcode(self,code_obj):
[...]
try:
self.hooks.pre_runcode_hook()
exec code_obj in self.user_global_ns, self.user_ns
finally:
# Reset our crash handler in place
sys.excepthook = old_excepthook
I would like a post_run_hook as well:
def runcode(self,code_obj):
[...]
try:
self.hooks.pre_runcode_hook() # my hook whould do:
simulation.lock.acquire()
exec code_obj in self.user_global_ns, self.user_ns
finally:
# Reset our crash handler in place
sys.excepthook = old_excepthook
self.hooks.post_runcode_hook() # my hook whould do:
simulation.lock.release()
I think I'll try monkey-patching for now, also because I still have 0.8.4 in
Ubuntu, but if some caring IPython developer would like to add the missing
hook then I might be able to drop my hack in a couple of years.. ;-)
Keep up the good work, and best regards.
--
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ipython.scipy.org/pipermail/ipython-user/attachments/20080927/cd5f3bcc/attachment.html
More information about the IPython-user
mailing list