问题是当我想从回调 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中文网其他相关文章!

2小时内可以学会Python的基本编程概念和技能。1.学习变量和数据类型,2.掌握控制流(条件语句和循环),3.理解函数的定义和使用,4.通过简单示例和代码片段快速上手Python编程。

Python在web开发、数据科学、机器学习、自动化和脚本编写等领域有广泛应用。1)在web开发中,Django和Flask框架简化了开发过程。2)数据科学和机器学习领域,NumPy、Pandas、Scikit-learn和TensorFlow库提供了强大支持。3)自动化和脚本编写方面,Python适用于自动化测试和系统管理等任务。

两小时内可以学到Python的基础知识。1.学习变量和数据类型,2.掌握控制结构如if语句和循环,3.了解函数的定义和使用。这些将帮助你开始编写简单的Python程序。

如何在10小时内教计算机小白编程基础?如果你只有10个小时来教计算机小白一些编程知识,你会选择教些什么�...

使用FiddlerEverywhere进行中间人读取时如何避免被检测到当你使用FiddlerEverywhere...

Python3.6环境下加载Pickle文件报错:ModuleNotFoundError:Nomodulenamed...

如何解决jieba分词在景区评论分析中的问题?当我们在进行景区评论分析时,往往会使用jieba分词工具来处理文�...

如何使用正则表达式匹配到第一个闭合标签就停止?在处理HTML或其他标记语言时,常常需要使用正则表达式来�...


热AI工具

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

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

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

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

热门文章

热工具

Atom编辑器mac版下载
最流行的的开源编辑器

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

Dreamweaver Mac版
视觉化网页开发工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

WebStorm Mac版
好用的JavaScript开发工具