当前位置: 动力学知识库 > 问答 > 编程问答 >

python - How to configure sched.run() to continue the program instead of waiting?

问题描述:

I have a Python code that registers a schedule task and should continue to execute the rest of the program (It placed on my server backend).

import sched, time

def pri():

print "A"

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

s.enter(60, 1, pri, ())

s.run

print "Hello"

I want the program to print Hello before executing the scheduled task, and continue the rest of the program.

Does anyone knows how to do that?

网友答案:

I solved it using threading:

import sched, time
import thread

def pri():
   print "A"

def schedule_task():
   s= sched.scheduler(time.time, time.sleep)
   s.enter(60, 1, pri, ())
   s.run

thread.create_new_thread(schedule_task, (,))
print "Hello"
分享给朋友:
您可能感兴趣的文章:
随机阅读: