こんにちは、私が抱えていた別のコードです。 私はデコレータを使用して、いくつかの機能を無期限に実行しています。デコレータとしてPyQtを使ったPythonスレッディング
ファイル:
from threading import Thread
from functools import wraps
def run(func):
@wraps(func)
def async_func(*args, **kwargs):
func_hl = Thread(target=func, args=args, kwargs=kwargs)
func_hl.daemon = False
func_hl.start()
return func_hl
return async_func
async.pyそして:
import async
[...]
@async.run
def foo():
while condition:
do_something()
しかし、今、私はQTおよびそれらのQThreadsでプロジェクトを作ります。
質問:私はデコレータをQTフレンドリーにするためにどうすればよいですか?私は醜いと間違って信じ
def better_thread(to_wrap):
class MyThread(QtCore.QThread):
def run(self, *args, **kwargs):
_res = to_wrap(*args, **kwargs)
return _res
@wraps(to_wrap)
def async_func(*args, **kwargs):
def finish():
pass
mythread = MyThread()
mythread.start()
result = mythread.run(*args, **kwargs)
return result
return async_func
: 私の努力は、これまでそのようなものでした。私たちを手伝ってくれますか?
PythonのスレッドがQtのと完璧に動作しますが、やりましたあなたは本当にこれが必要ですか? – Ceppo93
@ Ceppo93これらのスレッドの中にはguiを使用しているものがあるため、qtスレッドをシームレスな経験のために使いやすい方法にしています。 – pmus