我创建了两个模块,其中包含一些函数。我在module1中的一个函数中包含了两个函数,在module2中导入了module1,编译器中包含的函数often1
似乎没有执行
模块1
import time,thread
def class_often():
while 1<2:
time.sleep(5)
print "Custom funtion not often runs."
def class_often1():
while 1<2:
time.sleep(2)
print "Custom funtion often runs."
def compiler():
class_often()
class_often1()
模块2
import time,d,thread
def often():
while 1<2:
time.sleep(2)
print "funtion not often runs."
def often1():
while 1<2:
time.sleep(2)
print "Function often runs."
thread.start_new_thread(often,())
thread.start_new_thread(often1,())
thread.start_new_thread(d.compiler,())
在线程中启动编译器,但它调用
class_often
,因为它是一个无限循环,所以无法调用第二个函数:您还需要在
d.complier
中thread.start_new_thread
,即:更改后会产生如下输出:
在
thread
库上也建议使用threading lib相关问题 更多 >
编程相关推荐