简体   繁体   English

使用Python websocket-client多线程

[英]Using Python websocket-client multi threaded

Using Python websocket-client along with multiprocessing.Pool I'm able to spawn 3 instances of the websocket-client with each connected to a different URL and writing the data to 3 separate dictionaries. 结合使用Python websocket-client和multiprocessing.Pool,我能够生成3个websocket-client实例,每个实例都连接到不同的URL,并将数据写入3个单独的字典中。

My goal is to have a 4th process running that would be able to READ the data from all 3 dictionaries as they are updated. 我的目标是运行第4个进程,该进程将能够在更新所有3个字典时读取它们的数据。

What is the best way to share data between these processes? 在这些过程之间共享数据的最佳方法是什么?

I've looked at the multiprocessing examples but because a websocket.WebSocketApp takes a parameter that includes a function name to call (on_message) and it doesn't accept additional custom parameters, I'm not clear that the on_message functions would be able to be passed an instance of a Value or Pipe, etc. 我看过多处理示例,但是因为websocket.WebSocketApp接受了一个包含要调用的函数名称的参数(on_message),并且不接受其他自定义参数,所以我不清楚on_message函数是否能够传递或管道等的实例。

Multiprocessesing doesn't share data, so you would have to use a database of some sort. 多进程处理不会共享数据,因此您必须使用某种数据库。

I use gevent and the gevent-websocket library. 我使用gevent和gevent-websocket库。

https://pypi.python.org/pypi/gevent-websocket/ https://pypi.python.org/pypi/gevent-websocket/

You have two options, you can just run as many as you want asynchronously, OR you can use the GIPC module which actually multiprocesses gevent for you with the added benefit of being able to talk to each other through read write pipes. 您有两个选择,您可以异步运行任意多个,或者可以使用GIPC模块,该模块实际上为您处理gevent,并具有可以通过读写管道进行相互交谈的附加好处。

https://gehrcke.de/gipc/ https://gehrcke.de/gipc/

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM