I'm working on a application which connects with kernel module. for this communication i'm using netlink libnl3.5.0 in python which wraps "c" into py using swig. Problem is when I try do multiprocessing and trying to share the msg queue to different processes. Python is not able to pickle/serialize the messages which are in SwigPyObject format.
I tried to find the high level class implementation of this object but I'm confused. Saw other posts which says to implement some getstate and reduce functions in the object but I don't understand where to use this.
Tried dill package but I guess dill is using pickle for underlying implementations. so this is returning same error.
Below is main part of my implementation
def queue_packet(msg,args):
global a
nlh=nl.nlmsg_hdr(msg)
ghdr=genl.genlmsg_hdr(nlh)
if(ghdr.cmd==2):
_,attr=genl.py_genlmsg_parse(nlh,0,8,None)
a.put(attr)
#print(a.qsize())
return 0
def worker(a):
print("worker started")
while True:
if a.qsize()==0:
continue
attr=a.get()
process_messages_cb(attr)
a.task_done()
return 0
a=multiprocessing.Manager.Queue()
while 1:
nl.nl_recvmsgs(s,rx_cb)
This is main part of receiving and putting the messages to queue. and different workers will get the message from the queue and process them further. So how can I put the messages to queue to share between different workers/sub-processes. I'm using this https://github.com/thom311/libnl/tree/master/python API.
Thanks