在Django中使用线程库时发生异常

2024-09-27 07:22:41 发布

您现在位置:Python中文网/ 问答频道 /正文

一个在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)


Tags: djangorunindefexceptionthreadclasst1

热门问题