Python Forum
Speed up code with second process help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Speed up code with second process help
#1
Hi, iam trying to speed up my code by this way. But it is still not working fine. Let me tell you what iam doing.
I have two models that can process image for me. These images are frames from webcam (So it is realtime and it needs to be fast). When i run this serially in for loop it takes a lot of time - first process in model 1 and then in model 2. So i decided to make second process that will be processing image on second model. But i dont see any speed up so I suppose iam doing it wrong.

Can someone tell me what iam doing wrong ?


from multiprocessing.connection import Listener
from multiprocessing import Process
from multiprocessing.connection import Client


#My process that process image on model 1
def run():
    address = ('localhost', 6000)
    listener = Listener(address, authkey='secret password'.encode('utf-8'))
    conn = listener.accept()

    while True:
        try:
            msg = conn.recv()
            msg = process_model1(msg)
            conn.send(msg)
        except EOFError:
            pass


address = ('localhost', 6000)
client = Client(address, authkey='secret password'.encode('utf-8'))

for image in frames: # FRAMES ARE FROM WEBCAM, I NEED TO SPEED IT UP
    
    client.send(image)  # PROCESS IMAGE ON MODEL 1
    result_a = process_model2(image)  # PROCESS IMAGE ON MODEL 2
    result_b =  client.recv() # GET RESULT FROM PROCESS

    # Here iam just mixing results....


if __name__ == '__main__':
    p = Process(target=run)
    p.start()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Process finished with exit code 137 (interrupted by signal 9: SIGKILL) erdemath 2 9,518 Apr-18-2022, 08:40 PM
Last Post: erdemath
  Code taking too much time to process ErPipex 11 4,905 Nov-16-2020, 09:42 AM
Last Post: DeaD_EyE
  process finished with exit code -1073741819 (0xC0000005) GMCobraz 8 5,379 Sep-01-2020, 08:19 AM
Last Post: GMCobraz
  Python module speed or python speed in general Enrique6 1 1,834 May-04-2020, 06:21 PM
Last Post: micseydel
  How to sharing object between multiple process from main process using Pipe Subrata 1 3,654 Sep-03-2019, 09:49 PM
Last Post: woooee
  Process finished with exit code -107374819 (0xC0000375) mrazko 2 8,467 Apr-05-2019, 12:46 PM
Last Post: mrazko
  code pattern for process communication Skaperen 12 8,462 Oct-08-2017, 03:14 AM
Last Post: Skaperen
  Creating a program that records speed in a speed trap astonavfc 7 7,327 Nov-07-2016, 06:50 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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