How do I set up a timer as a subprocess?

D

Dfenestr8

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?
 
D

Daniel Schüle

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,222
Messages
2,571,140
Members
47,755
Latest member
Grazynkaa

Latest Threads

Top