由于某种原因代码没有到达main函数。我使用cloud9来运行代码,这可能是问题所在。
from multiprocessing import Process, Value
import time
def main():
print "main function"
def market_price_thread():
while True:
market_price()
time.sleep(5)
def market_price():
#do something
print "end"
def start_threads():
thread = Process(target=market_price_thread())
thread.start()
time.sleep(5)
if __name__ == '__main__':
start_threads()
main() #does not seem to get to this
答案 0 :(得分:1)
您已要求Python拨打market_price_thread
:
thread = Process(target=market_price_thread())
然后使用它返回的任何值作为target
值。因此,在致电Process
之前,我们必须等待market_price_thread
返回。它返回什么价值,何时返回?
(与Process(target=market_price_thread)
比较,不调用market_price_thread
,而是将该函数传递给Process
,以便Process
可以叫它。)