从字面上解释您的描述,您需要在调用之前放置print语句func2().
但是,我猜你真正想要的是func2()一个后台任务,它允许func1()立即返回而不是等待func2()完成它的执行.为此,您需要创建一个要运行的线程func2().
import time
import threading
def func1():
t = threading.Thread(target=func2)
t.start()
print("Do stuff here")
def func2():
time.sleep(10)
print("Do more stuff here")
func1()
print("func1 has returned")
Run Code Online (Sandbox Code Playgroud)
你可以使用threading.Timer:
from __future__ import print_function
from threading import Timer
def func1():
func2()
print("Do stuff here")
def func2():
Timer(10, print, ["Do more stuff here"]).start()
func1()
Run Code Online (Sandbox Code Playgroud)
但正如@unholysampler已经指出的那样,写一下可能会更好:
import time
def func1():
print("Do stuff here")
func2()
def func2():
time.sleep(10)
print("Do more stuff here")
func1()
Run Code Online (Sandbox Code Playgroud)