#!/usr/bin/env python """A stripped down version of Fernando Perez's multi-threaded shell Demonstrates a bug in the readline module causing the Python interpreter to segfault""" __author__ = ["Fernando Perez ", "Yariv Ido "] import code import threading import time import readline import rlcompleter class MTConsole(code.InteractiveConsole): """Simple multi-threaded shell""" def __init__(self, *args, **kw): code.InteractiveConsole.__init__(self,*args,**kw) readline.parse_and_bind('tab: complete') def doNothing(self): # Allow other threads to run time.sleep(0) class SegFaultInterpreter(threading.Thread): def __init__(self): super(SegFaultInterpreter, self).__init__() self.shell = MTConsole() def run(self): self.shell.interact("Rapidly press 'TAB' a couple of times") def mainloop(self): self.start() while True: self.shell.doNothing() if __name__ == '__main__': SegFaultInterpreter().mainloop()