Python Forum
How to sharing object between multiple process from main process using Pipe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to sharing object between multiple process from main process using Pipe
#1
I try to call multiprocessing to act my process faster.
At the moment I face some problems sharing some data with many processes from main process.
I use multiprocess.pipe() to pass the data.

I use multiprocess.manager to pass the data.

1. Initialization:-



<

try:
global devices
self.listofwritetags = self.collectwritetaglist()
conn1, conn2 = multiprocessing.Pipe()
devices = bussiness.initilaztion(self.comm_object,logger)
conn1.send(devices)
self.callmotor1dprocess =
multiprocessing.Process(target=callallmotor1d,args=[conn2])
self.listofthread.append(self.callmotor1dprocess)





2.Start and stop process:-



def startprocess(self):
for item in self.listofprocess:
item.start()


def stopprocess(self):
for item in self.listofprocess:
item.terminate()



UI:-




self.button3 = ttk.Button(self.frame, text='Start', command=self.startprocess,state =NORMAL)
self.button3.grid(column=1, row=4, sticky=W,padx=5, pady=5)

self.button4 = ttk.Button(self.frame, text='Stop', command=self.stopprocess, state=NORMAL)
self.button4.grid(column=1, row=5, sticky=W, padx=5, pady=5)



I need to call avobe 3 process in one class:- FormUI

but I call executable process outside of the FormUI class.

I got an error when I try to initialize.I want to pass devices from main process to child process.

The calling method:-





def callallmotor1d(conn):
devices = conn.recv()
bussiness.motorallprocessing(devices)



def callallsov1s(conn):
devices = conn.recv()
bussiness.motorallprocessing(devices)





Any help regarding this would be appreciable


Error messege:-

2019-09-03 13:15:33,755: can't pickle _thread.lock objects
Traceback (most recent call last):
File "C:/Users/misu01/PycharmProjects/opcua/ui_v7.py", line 226, in initilization
conn1.send(devices)
File "C:\Users\misu01\AppData\Local\Programs\Python\Python37\lib\multiprocessing\connection.py", line 206, in send
self._send_bytes(_ForkingPickler.dumps(obj))
File "C:\Users\misu01\AppData\Local\Programs\Python\Python37\lib\multiprocessing\reduction.py", line 51, in dumps
cls(buf, protocol).dump(obj)
TypeError: can't pickle _thread.lock objects
Reply
#2
self.listofprocess has not been declared anywhere in the code you posted
def startprocess(self):
    for item in self.listofprocess:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to automate the process br0oJ 0 222 Feb-14-2024, 12:01 PM
Last Post: br0oJ
  Best way to secure API key when sharing quarinteen 2 289 Jan-19-2024, 04:46 PM
Last Post: deanhystad
  How should I process this data? SuchUmami 2 346 Jan-13-2024, 05:30 PM
Last Post: RockBlok
  How would I process this data? SuchUmami 2 511 Nov-12-2023, 10:05 AM
Last Post: SuchUmami
  Create csv file with 4 columns for process mining thomaskissas33 3 691 Nov-06-2023, 09:36 PM
Last Post: deanhystad
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,046 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Question about Creating an Automated Process in Python Supratik1234 0 712 Jan-13-2023, 08:29 PM
Last Post: Supratik1234
  Convert Excel file into csv with Pipe symbol.. mg24 4 1,288 Oct-18-2022, 02:59 PM
Last Post: Larz60+
  Failed to execute child process (No such file or directory) uriel 1 1,614 Sep-15-2022, 03:48 PM
Last Post: Gribouillis
  How to make app run only when process is aviable Mawixy 1 1,143 Apr-19-2022, 03:45 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020