来自回调 tkinter 的多处理
问题是当我想从回调 tkinter(特别是函数 tkinter 的绑定)触发进程“多重处理”时。错误从这里开始:
file“c:usersusuariodownloadsengine_controller_lsextracttextfuncionesreproductor.py”,第 598 行,在 __init__ p.start() 文件“c:program filespython311libmultiprocessingprocess .py”,第 121 行,开始 self._popen = self._popen(self) ^^^^^^^^^^^^^^^^^^ 文件“c:program filespython311libmultiprocessing context.py”,第 224 行,在 _popen 中返回 _default_context.get_context().process._popen(process_obj) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 文件“c:program filespython311libmultiprocessingcontext.py”,第 336 行,在 _popen 返回 popen(process_obj) ^^^^^^^^^^^^^^^^^^^ 文件 "c:program filespython311libmultiprocessingpopen_spawn_win32.py",第 95 行,在 __init__duction.dump(process_obj, to_child) 文件“c:program filespython311libmultiprocessingreduction.py”中,第 60 行,在转储 forkingpickler(file, protocol).dump(obj) 中 typeerror: 无法 pickle ' _tkinter.tkapp'对象
main.py
from reproductor import mediaplayer def item_selected(event): """ evento invocado cuando el contenido de una carpeta es abierto. """ item_seleccionado = arbol.selection() item = arbol.item(item_seleccionado) print(item) #extraer la ruta del archivo y si encuentra espacios unirlos ruta = "" for element in item["values"]: ruta += element + " " #iniciacion del video global reproductor_video # cerrar el video para que no se abra en multiples ventanas if reproductor_video is not none: reproductor_video.closeplayer() reproductor_video = mediaplayer(ruta, frame_visualizer, frame_botones_procesar, spininicio=inbox_inicio, spinfinal=inbox_fin, spinactual=inbox_actual, mainvideo=true) reproductor_video.update_progres_video() arbol = checkboxtreeview(frame_tree_in) arbol.bind("<<treeviewselect>>", item_selected)
reproductor.py
class MediaPlayer: def __init__(ruta, frame_visualizer, frame_botones_procesar, spinInicio=inBox_inicio, spinFinal=inBox_fin, spinActual=inBox_Actual, mainVideo=True): p = Process(target=self.funcion1) p.start() #p.join def funcion1(self): cont = 0 while cont < 100: cont += 1 print("contador =", cont)
我在主函数中尝试了相同的代码,并且它执行得很好,但是从回调中它不会执行。
正确答案
原版
解决方案在这里为那些需要它的人提供,实际上,如果它可以从 tkinter 上的事件启动,如下所示:
翻译(谷歌翻译):
解决方案在这里为那些需要它的人提供,事实上它可以从 tkinter 中的事件启动,如下所示:
from multiprocessing import Process, log_to_stderr, get_logger import time from tkinter import Tk from tkinter import ttk import logging import sys def item_selected(event): my_objeto = objeto() button_eraser.config(command=lambda:my_objeto.lanzador(2)) button_marco.config(command=lambda:my_objeto.lanzador(1)) my_objeto.start_player() class objeto: def __init__(self) -> None: #self.start_player() pass def start_player(self): pass def funcion1(self): contador = 0 while 1: contador += 1 print("Func1: ", contador, self.palabra) time.sleep(0.1) if contador > 80: break q = Process(target=self.funcion3) q.start() #q.join() def funcion2(self): contador = 0 while 1: contador += 2 print("Func2: ", contador) time.sleep(0.2) if contador > 120: break def funcion3(self): contador = 0 while 1: contador += 2 print("Func3: ", contador) time.sleep(0.02) if contador > 200: break def lanzador(self,mode): log_to_stderr(logging.DEBUG) logger = get_logger() logger.setLevel(logging.INFO) if mode == 1: self.p = Process(target=self.funcion1) self.p.start() elif mode == 2: self.p = Process(target=self.funcion2) self.p.start() def unir(self): self.p.join() print("Salio") def iniciar_multis(self): self.lanzador(2) self.lanzador(1)
以上是来自回调 tkinter 的多处理的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

本教程演示如何使用Python处理Zipf定律这一统计概念,并展示Python在处理该定律时读取和排序大型文本文件的效率。 您可能想知道Zipf分布这个术语是什么意思。要理解这个术语,我们首先需要定义Zipf定律。别担心,我会尽量简化说明。 Zipf定律 Zipf定律简单来说就是:在一个大型自然语言语料库中,最频繁出现的词的出现频率大约是第二频繁词的两倍,是第三频繁词的三倍,是第四频繁词的四倍,以此类推。 让我们来看一个例子。如果您查看美国英语的Brown语料库,您会注意到最频繁出现的词是“th

本文解释了如何使用美丽的汤库来解析html。 它详细介绍了常见方法,例如find(),find_all(),select()和get_text(),以用于数据提取,处理不同的HTML结构和错误以及替代方案(SEL)

处理嘈杂的图像是一个常见的问题,尤其是手机或低分辨率摄像头照片。 本教程使用OpenCV探索Python中的图像过滤技术来解决此问题。 图像过滤:功能强大的工具 图像过滤器

PDF 文件因其跨平台兼容性而广受欢迎,内容和布局在不同操作系统、阅读设备和软件上保持一致。然而,与 Python 处理纯文本文件不同,PDF 文件是二进制文件,结构更复杂,包含字体、颜色和图像等元素。 幸运的是,借助 Python 的外部模块,处理 PDF 文件并非难事。本文将使用 PyPDF2 模块演示如何打开 PDF 文件、打印页面和提取文本。关于 PDF 文件的创建和编辑,请参考我的另一篇教程。 准备工作 核心在于使用外部模块 PyPDF2。首先,使用 pip 安装它: pip 是 P

本教程演示了如何利用Redis缓存以提高Python应用程序的性能,特别是在Django框架内。 我们将介绍REDIS安装,Django配置和性能比较,以突出显示BENE

本文比较了Tensorflow和Pytorch的深度学习。 它详细介绍了所涉及的步骤:数据准备,模型构建,培训,评估和部署。 框架之间的关键差异,特别是关于计算刻度的

Python是数据科学和处理的最爱,为高性能计算提供了丰富的生态系统。但是,Python中的并行编程提出了独特的挑战。本教程探讨了这些挑战,重点是全球解释

本教程演示了在Python 3中创建自定义管道数据结构,利用类和操作员超载以增强功能。 管道的灵活性在于它能够将一系列函数应用于数据集的能力,GE
