[英]How to create a socket object using multiprocessing and pass it back to the parent process
I wish to create a sock.Socket object from a main program using multiprocessing to avoid blocking the main program if the socket is not available during the creation process. 我希望使用多重处理从主程序创建一个sock.Socket对象,以避免在创建过程中套接字不可用时阻塞主程序。 The socket gets created but can not be returned to the main program. 套接字已创建,但无法返回到主程序。
After some reading it seems that objects can not be shared between python processes. 经过一番阅读后,似乎无法在python进程之间共享对象。 It there a possible design pattern to circumvent this? 有没有可能避免这种情况的设计模式? Is multiprocessing suitable for this application or should I be considering another approach? 多重处理是否适合此应用程序,或者我应该考虑另一种方法?
You should keep it really simple and have a socket handler thread which: 您应该使其非常简单,并具有一个套接字处理程序线程,该线程:
Then everything becomes non-blocking. 然后,一切都变得无阻塞。 This is a much cleaner design pattern especially if you use pubsub. 这是一种更加简洁的设计模式,尤其是在使用pubsub的情况下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.