Hello fellow Overflowers, here's another code I've stuck in. I am using decorator to run some functions asycronously.
file: async.py
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
And then:
import async
[...]
@async.run
def foo():
while condition:
do_something()
But now I make a project with QT and those QThreads.
So,the question is: how should I improve my decorator to be QT-friendly? My effort so far was like that:
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
Which I beleive is ugly and wrong. Could you help me?