def loop_cocoa(kernel):
import matplotlib<EOL>if matplotlib.__version__ < '<STR_LIT>':<EOL><INDENT>kernel.log.warn(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL>return loop_tk(kernel)<EOL><DEDENT>from matplotlib.backends.backend_macosx import TimerMac, show<EOL>poll_interval = int(<NUM_LIT:1000>*kernel._poll_interval)<EOL>real_excepthook = sys.excepthook<EOL>def handle_int(etype, value, tb):<EOL><INDENT>"""<STR_LIT>"""<EOL>if etype is KeyboardInterrupt:<EOL><INDENT>io.raw_print("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>real_excepthook(etype, value, tb)<EOL><DEDENT><DEDENT>def doi():<EOL><INDENT>sys.excepthook = real_excepthook<EOL>kernel.do_one_iteration()<EOL>sys.excepthook = handle_int<EOL><DEDENT>t = TimerMac(poll_interval)<EOL>t.add_callback(doi)<EOL>t.start()<EOL>poller = zmq.Poller()<EOL>if kernel.control_stream:<EOL><INDENT>poller.register(kernel.control_stream.socket, zmq.POLLIN)<EOL><DEDENT>for stream in kernel.shell_streams:<EOL><INDENT>poller.register(stream.socket, zmq.POLLIN)<EOL><DEDENT>while True:<EOL><INDENT>try:<EOL><INDENT>try:<EOL><INDENT>sys.excepthook = handle_int<EOL>show.mainloop()<EOL>sys.excepthook = real_excepthook<EOL>poller.poll(<NUM_LIT:10>*poll_interval)<EOL>kernel.do_one_iteration()<EOL><DEDENT>except:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>except KeyboardInterrupt:<EOL><INDENT>io.raw_print("<STR_LIT>")<EOL><DEDENT>finally:<EOL><INDENT>sys.excepthook = real_excepthook<EOL><DEDENT><DEDENT>
Start the kernel, coordinating with the Cocoa CFRunLoop event loop
    via the matplotlib MacOSX backend.