【发布时间】:2020-06-28 19:56:46
【问题描述】:
我有一个程序可以获取音频文件并对其进行处理。
@app.route('/', methods=['GET', 'POST'])
def hello_world():
if request.method == 'GET':
return render_template('upload.html')
else:
file = request.files['file']
path = os.getcwd() + '\\tempFilesAudio\\'
if not os.path.exists(os.getcwd() + '\\' + 'tempFilesAudio'):
os.mkdir(os.getcwd() + '\\' + 'tempFilesAudio')
if not os.path.exists(os.getcwd() + '\\' + 'tempFilesTransciption'):
os.mkdir(os.getcwd() + '\\' + 'tempFilesTransciption')
file.save(path + secure_filename(file.filename))
file_path = path + file.filename
conv_path = convert(file_path)
print('converted:{}'.format(conv_path))
#this is a thread
Recogniser(conv_path)
print('Deleting MP3')
os.remove(file_path)
print('Deleting WAV')
os.remove(conv_path)
return render_template('upload.html')
我希望在文件提交给线程以在后台处理后重新渲染我的 UI。但它仍在等待。
下面是我的帖子的代码:
class Recogniser:
def __init__(self, file):
self.executor = ThreadPoolExecutor(5)
self.file = file
thread = threading.Thread(target=self.run(), daemon=True, args=file)
thread.start()
def run(self):
#something
【问题讨论】:
标签: python python-multithreading background-thread