我正在尝试使用Python的多处理过程包(Raspbian9上的Python3.5-Stretch)。你知道吗
以下内容可以作为独立程序或在使用Python的线程包的线程中完美地工作。但是,它不适用于多处理过程. 你知道吗
是我遗漏了什么,还是PubNub的SubscribeListener与Python的多处理包不兼容?你知道吗
#!/usr/bin/env python3
from pubnub.pubnub import PubNub, SubscribeListener
from pubnub.pnconfiguration import PNConfiguration
import multiprocessing
import time
def PN_func():
pnconfig = PNConfiguration()
pnconfig.subscribe_key = 'sub-mykey'
pubnub = PubNub(pnconfig)
print('Pubnub multiprocess subscriber initiated...')
class Listener(SubscribeListener):
def message(self, pubnub, data):
print("From Multiprocess function message: ", data.message)
pubnub.add_listener(Listener())
pubnub.subscribe().channels('my_channel').execute()
if __name__ == '__main__':
mp = multiprocessing.Process(target=PN_func)
mp.start()
mp.join()
PubNub和Python多处理
我无法让SDK在多处理工作进程中处理同步请求。不过,以下技巧非常有效:
同时使用多处理和PubNub
简单
example.py
文件包含以下代码:多处理子进程的输出
相关问题 更多 >
编程相关推荐