通过 共享内存 和其他进程通信
try: log.info('fireworks_plugin start') shm = shared_memory.SharedMemory(create=False, size=mem_share_size, name='fireworksShareMemory') with Pair0(dial=address) as s1: s1.send(b'python login') while True: msg = s1.recv().decode(encoding='utf-8') print('python:' + msg) log.info('receive: ' + msg) if msg == 'exit': s1.send(b'python bye') time.sleep(0.5) log.info('exit nng loop') break elif msg.startswith('datas') or msg.startswith('ready'): log.info('receive ' + msg) param_list = msg.split(',') if len(param_list) >= 4: data_size = int(param_list[1]) load_share_data(shm, data_size) if param_list[2] == param_list[3]: log.info('get last group data') ret = proc_raw_data(share_df_list) print('Python datas_RESULT,' + ''.join(ret)) log.info('datas_RESULT,' + ''.join(ret)) s1.send(bytes('datas_RESULT,' + ''.join(ret), encoding='gbk')) else: s1.send(b'datas_OK') pass
shm.close() shm.unlink() log.info('exit plugin') except Exception as e: import traceback traceback.print_exc() errMsg = traceback.format_exc() print("Error: " + errMsg) log.error("call plugin exception." + errMsg) except: import traceback
traceback.print_exc() errMsg = traceback.format_exc() print("Error: " + errMsg) log.error("call plugin exception." + errMsg)
|