So I'm writing a bit of code for use in an IRC bot. I tried to use scheduler to get around the barbaric-ness of calling time.sleep() every time I want the bot to delay for a few seconds. In scheduler you can choose the delay function "for example time.sleep()"-- but I haven't found any mention of other delay functions anywhere on the net.

Being an IRC bot it's important that it can receive pings and distribute pongs when necessary. time.sleep(), however, pauses the entire .py, rendering the ping/pong lines irrelevant and ultimately leading to a ping timeout.

import time
import sched

snip

c=sched.scheduler(time.time, time.sleep)

snip

x=msg
                        if(int(x)>=30):
                            def xsc(x):
                                swrite("JOIN "+chan)
                                privmsg(chan, "I'm back after a "+x+" second sleave!")
                            swrite("PART "+chan)
                            c.enter(float(x), 1, xsc, (x,))
                            c.run()
                        else:
                            privmsg(chan, "At least a 30 second kick, please ;).")

time.sleep(), however, pauses the entire .py, rendering the ping/pong lines irrelevant and ultimately leading to a ping timeout.

If I understand the question, you would use threading or multiprocessing to run the code that you don't want to sleep/pause. Since it runs as a separate process, time.sleep() won't affect it.

Edited 6 Years Ago by woooee: n/a

This article has been dead for over six months. Start a new discussion instead.