By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,100 Members | 2,495 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,100 IT Pros & Developers. It's quick & easy.

How do I set up a timer as a subprocess?

P: n/a
Hi.

Trying to set up a timer function for my irc bot, which uses the python
irclib.py.

If I use time.sleep(20), it tends to freeze up the bot completely for 20
secs. That's not what I want though! I want the program to wait 20 secs,
then perform another function, but in the meantime be able to accept other
commands.

How do I do that?
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi
Trying to set up a timer function for my irc bot, which uses the python
irclib.py.

If I use time.sleep(20), it tends to freeze up the bot completely for 20
secs. That's not what I want though! I want the program to wait 20 secs,
then perform another function, but in the meantime be able to accept other
commands.

How do I do that?


if I understand properly what you want to achieve, you will need to
setup a separate execution thread

import thread

def f1():
return "hallo"

def f2():
return " World"

func_list = [f1, f2, lamda : "!!!"]

def otherThread(sec):
import time
for i in func_list:
print i(),
time.sleep(sec)

thread.start_new_thread(otherThread, (20, ))

print "meanwhile print this message"
i = raw_input("or let the user give some instructions")
def xx():
pass
xx()

i hope this is what you are looking for
my code is however untested, but should work
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.