一个在Django的新手
在Django中使用基本线程时,我遇到了一些问题
这是我的剧本
from threading import Thread
def run_threads(msg1, msg2):
class Hello(Thread):
def run(self):
for i in range(500):
print(msg1)
class Hi(Thread):
def run(self):
for i in range(500):
print(msg2)
t1 = Hello()
t2 = Hi()
t1.start()
t2.start()
t1.join()
t2.join()
print("Here")
但在运行时,它给了我以下错误
somethingException in thread Exception in threading.excepthook:Exception ignored in thread started byException ignored in sys.unraisablehookis cookingException in thread Exception in threading.excepthook:E
xception ignored in thread started byException ignored in sys.unraisablehookHere
但如果我在Python3控制台中运行它而不使用Django,它就可以正常工作。任何帮助都将不胜感激
有关我的系统的信息:
Python:3.8
Django:(3, 1, 4, 'final', 0)
经过研究,我决定与我的应用程序进行芹菜集成,并在Django中异步运行任务,作为线程。希望这对其他人也有帮助
您可以使用sync\u to\u异步方法或芹菜库 https://docs.djangoproject.com/en/3.1/topics/async/https://docs.celeryproject.org/en/stable/django/first-steps-with-django.html
相关问题 更多 >
编程相关推荐