[英]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:是可行的,看看:
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.