parser.add_argument("--debug", action="store_true", default=False) args = parser.parse_args() if args.debug: import simplelogging.logsetup simplelogging.logsetup.setup_console() def closed(): print("closed") reactor.callFromThread(reactor.stop) con = Monkey(args.connection, args.address, callback_reactor=reactor) con.set_closed_callback(closed) if args.channel is not None: reactor.callFromThread(con.set_channel, args.channel) pinger = PingSender(con, args) con.open() pinger.start() # Run the system reactor.run() con.close() printgreen("done")