469,327 Members | 1,242 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

How do I set up a timer as a subprocess?

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
1 1646
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.

Similar topics

4 posts views Thread by Marc Carter | last post: by
2 posts views Thread by Stewart Midwinter | last post: by
3 posts views Thread by Darren Dale | last post: by
5 posts views Thread by Cameron Laird | last post: by
5 posts views Thread by Grant Edwards | last post: by
9 posts views Thread by Phoe6 | last post: by
10 posts views Thread by JD | last post: by
12 posts views Thread by bhunter | last post: by
7 posts views Thread by skunkwerk | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.