def cmd(send, msg, args): """Cancels a deferred action (i.e. kills a thread) with the given name. Syntax: !cancel thread-name """ if not args['is_admin'](args['nick']): send("Only admins can cancel threads.") return try: thread = get_thread(int(msg)) except ValueError: send("Thread ident must be a number.") return if thread is None: send("I couldn't find any thread matching that name.") return thread[1].set() thread[0].join() send("Thread canceled.")
def _defer(t, function, args): add_thread(current_thread()) if not get_thread(get_ident())[1].wait(int(t)): function(*args)