python多线程执行方法问题

问题描述:需要同时运行2个方法, # interface_process.run_usb_random_write()
# usb_mapping_test.main(is_flag) 测试是可以正常运行成功的。但是会报错。


class Test:
    def main(self, is_flag, case_list):
        usb_path = tools.get_usb_dispart()
        usb_mapping_test = UsbMappingTest()
        usb_rep_insertion = UsbRepInsertion()
        if "writing_dis_usb" in case_list:
            is_flag = False
# interface_process.run_usb_random_write()
            # usb_mapping_test.main(is_flag)

            thread1 = threading.Thread(target=interface_process.run_usb_random_write)
            thread2 = threading.Thread(target=usb_mapping_test.main, args=(is_flag,))
            thread1.start()
            thread2.start()
            thread1.join()
            thread2.join()

报错信息如下


Exception ignored in: <function Image.__del__ at 0x000002703819A670>
Traceback (most recent call last):
  File "H:\software\miniconda3\envs\py3.8\lib\tkinter\__init__.py", line 4017, in __del__
    self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Exception ignored in: <function Variable.__del__ at 0x000002703815DD30>
Traceback (most recent call last):
  File "H:\software\miniconda3\envs\py3.8\lib\tkinter\__init__.py", line 363, in __del__
    if self._tk.getboolean(self._tk.call("info", "exists", self._name)):
RuntimeError: main thread is not in main loop
Exception ignored in: <function Variable.__del__ at 0x000002703815DD30>
Traceback (most recent call last):
  File "H:\software\miniconda3\envs\py3.8\lib\tkinter\__init__.py", line 363, in __del__
    if self._tk.getboolean(self._tk.call("info", "exists", self._name)):
RuntimeError: main thread is not in main loop
Exception ignored in: <function Variable.__del__ at 0x000002703815DD30>
Traceback (most recent call last):
  File "H:\software\miniconda3\envs\py3.8\lib\tkinter\__init__.py", line 363, in __del__
    if self._tk.getboolean(self._tk.call("info", "exists", self._name)):
RuntimeError: main thread is not in main loop
Exception ignored in: <function Variable.__del__ at 0x000002703815DD30>
Traceback (most recent call last):
  File "H:\software\miniconda3\envs\py3.8\lib\tkinter\__init__.py", line 363, in __del__
    if self._tk.getboolean(self._tk.call("info", "exists", self._name)):
RuntimeError: main thread is not in main loop
Tcl_AsyncDelete: async handler deleted by the wrong thread

你这个大概是什么应用场景?因为你调了很多自己封装的库哈。还有你的需求背景是什么,完了我本地好调试模拟一下

测试用例:需要实现,U盘读写中,然后进行U盘的映射,和弹出。这个历程的测试。
场景实现:存在A物理电脑和B虚拟云电脑。A电脑中插入U盘,远程到B电脑后,可以在远程工具栏中,点击映射,然后将A电脑中插入的U盘映射到B电脑中。
当前测试流程:

1.B电脑中启动了一个falsk服务,存在2个接口,一个是复制脚本接口,一个是执行脚本的接口。interface_process.run_usb_random_write() 这方法中调用了2个接口,一个接口是将A电脑项目中的脚本上传到B电脑,然后发送脚本执行命令到B电脑进行执行。 脚本是检测到U盘后,会针对U盘进行随机写入操作。
2.usb_mapping_test.main(is_flag) 这个接口,会进行UI操作,从A电脑点击连接到B电脑,再点击映射,断开,一些类UI操作。 这个期间,再映射成功后,被控运行的脚本,会进行随机写入操作,。也就实现了----U盘读写中,然后进行U盘的映射,和弹出。这个场景。