from threading import Thread from random import randint from time import sleep class Crasher(Thread): def __init__(self, file): self.file = file self.done = False Thread.__init__(self) def run(self): raw = self.file.buffer while not self.done: try: line = self.file.readline() if not line: self.file.seek(0) sleep(randint(1, 50)/1000.0) except IOError as err: print(err) def main(): import io mode = "rU" out = io.open(__file__, mode, encoding="latin-1") threads = [Crasher(out) for index in range(32)] print("start") for thread in threads: thread.start() try: for step in range(30): print("wait the crash...") sleep(1) except KeyboardInterrupt: pass print("stop!") for thread in threads: thread.done = True main()