简体   繁体   English

是否可以在 class 中线程化子类?

[英]Is it possible to thread a subclass within a class?

This is for a moderation bot for C&C Renegade, in case anyone wants some background.这是用于 C&C Renegade 的审核机器人,以防有人需要一些背景知识。

I have a class which will act as a parent to a load of subclasses that provide IRC connections, connections to the gamelog (UDP socket), etc, and I want to know if it is possible to split some of these subclasses (notably the two socket connections [IRC, gamelog]) into their own threads using the threading module.我有一个 class 它将充当提供 IRC 连接、游戏日志连接(UDP 套接字)等子类负载的父类,我想知道是否可以拆分其中一些子类(特别是两个socket connections [IRC, gamelog]) 使用 threading 模块进入它们自己的线程。

If anyone has any suggestions, even if it's just saying it can't be done, I'd appreciate the input.如果有人有任何建议,即使只是说无法完成,我也会很感激。

Tom汤姆

Edit: I have experience with working with threaded applications, so I'm not a complete noob, honest.编辑:我有使用线程应用程序的经验,所以我不是一个完整的菜鸟,老实说。

It is feasible, take a look at:是可行的,看看:

multiprocessing多重处理

Besides the simple process forking, it also provides memory sharing - which is likely to be needed.除了简单的进程分叉,它还提供 memory 共享——这很可能是需要的。

The best option would be to run your app with gevent coroutines.最好的选择是使用gevent协同程序运行您的应用程序。 Those are much more light-weight than threads and processes.这些比线程和进程轻得多。 The library has been created based on green threads execution units.该库是基于绿色线程执行单元创建的。 Here you can find a good comparison and benchmark of the execution models of Eventlet (A python library that provides a synchronous interface to do asynchronous I/O operations which uses green threads to achieve cooperative sockets) and node.js. 在这里您可以找到 Eventlet 的执行模型(一个 python 库,提供同步接口来执行异步 I/O 操作,使用绿色线程实现协作套接字)和 node.js 的执行模型的一个很好的比较和基准。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在python中初始化类中的子类 - Initialize subclass within class in python Python - 在 Process 子类中创建 Thread 子类的问题 - 线程和多处理 - Python - Issue with creating a Thread subclass within a Process subclass - threading & multiprocessing 是否可以在子类中将数据属性分配给超类? - Is it possible to assign a data attribute to a superclass, within a subclass? 实例是一个“对象”,但类不是“对象”的子类:这怎么可能? - Instance is an “object”, but class is not a subclass of “object”: how is this possible? 是否可以从父类调用子类的函数? - Is it possible to call a function of a subclass from parent class? 从基类中设置子类变量/属性 - Set Subclass Variables/Attributes from Within Base Class 在主 class 的子类中创建的 PyQt5 小部件的设置属性 - Setting attribute of a PyQt5 widget created in a subclass within the main class 是否可以从python的子线程中杀死父线程? - Is it possible to kill the parent thread from within a child thread in python? 是否可以与父类实例共享在子类实例中定义的方法引用? - Is it possible to share a method reference defined in subclass insatnces with instances of the parent class? 是否可以继承不可变日期 class 并覆盖 __str__ 方法? - Is it possible to subclass the immutable date class and override the __str__ method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM