def __init__(self, ignoreempty=False): if (Readline.singleton): raise Exception, 'only one Readline agent may exist' sched.Agent.__init__(self) self.prompt = '> ' self.ignoreempty = ignoreempty self.incomplete = '' try: readline.set_erase_empty_line(1) readline.set_event_hook(event_hook) readline.set_startup_hook(startup_hook) except: print """ Hello, Pythoneer! This is the zymb.readlineagent module. I need some features which your standard Python readline module does not support. Go to <http://www.eblong.com/zarf/zymb/> for my hacked-up readline code. I apologize for the inconvenience. """ raise Readline.singleton = self
this module "owns" SIGALRM, and all timing functions associated with it. This means that you should not use the stock time.sleep() function when using this module. Instead, use get_scheduler().sleep(x) to sleep. """ import signal from errno import EINTR from pycopia import itimer alarm = itimer.alarm # allows subsecond precision using floats # enables custom readline module to process Python signal handlers when idle import readline try: readline.set_event_hook(lambda:None) except AttributeError: pass # not a modified readline module :-( del readline __all__ = ["get_scheduler"] # Save a function call by making a simple reference. sleep = itimer.absolutesleep def insort(a, x, lo=0, hi=None): if hi is None: hi = len(a) while lo < hi: mid = (lo+hi) // 2 if x < a[mid]:
def get_poller(): global poller return poller # a singleton instance of the SIGIOHandler. Usually, users of this module only # have to register a DirectoryNotifier object here. Other objects (Dispatcher # objects) are registered with the poller (which is already set up to be called # when SIGIO occurs). But you may add your own hooks to it. manager = None def start_sigio(): global manager if manager is None: manager = SIGIOHandler() # add the local poller instance to the signal handler. manager.register(lambda: poller.poll(0)) else: manager.on() def stop_sigio(): global manager if manager is not None: manager.off() start_sigio() import readline readline.set_event_hook(lambda: poller.poll(0)) del readline