Python- Example One simulated DMM in Multiprocessing with Lock

showing why lock is need if you have multiple process (uuts to test) but only One DMM

Focus is on Multiprocessing and Lock (not on DMM communication setup)

code for Python3.7 used in Spyder

# -*- coding: utf-8 -*-
Created on Sat Mar 18 14:32:12 2023

@author: aleja

from multiprocessing import Process,Queue,Lock
import time

def DMM_Voltage(UUT_Slot,UUT_Ch,lock_dmm,qu):
        # only ONE dmm so LOCK  (before lock 1sec) (after 4sec) each but each process was call its own dmm_volt
        #which in real use is a problem ONE DMM lock force function to block other use dmm_volt
        # in this simulation you alway see correct meas BUT in real dmm imagen dmm getting different uuts reading
        time.sleep(0.000001)  #for me the lock needed time to enforce will try to move into  test uut to see diff
        qu.put(("setting up DMM mux for UUT:"+str(UUT_Slot)+"\n"))
        meas_Volts=(UUT_Slot*10)+UUT_Ch #simple voltage
        return meas_Volts

def Test_UUT(Slot,UUT_Ch_List,qu,lock_dmm):
            start_t = time.time()
            for UUT_Channel in UUT_Ch_List: 
             str1=("UUT: "+ str(Slot)+ " Ch: " + str(UUT_Channel) + " Meas: "+ str(Measure)+"\n")
            # this will not not print in spyder console print("inside Test UUT")
            end_t = time.time()
            str1=("Slot Finished: " + str(Slot)+ " delta time:" + str(delta_t)+"\n")
            return (str1)
if __name__=="__main__":
        #for Slot in UUT_Slot_List:
        #need a better way to lanuch same process multiple times
        pList = [Process(target=Test_UUT, args=(UUT_Slot_List[i],UUT_Channel_List,qu,lock_dmm,)) for i in range(Num_of_UUTs)]
        for p in pList:
        # not this one   start_t = time.process_time() 
        start_t = time.time() 
        for p in pList:           
        end_t = time.time()
        print("total delta time" + str(end_t-start_t) + "\n")
        while not qu.empty():

End Code


  • Presentation: example One DMM and Python Multiprocessing w Lock
  • Programming Language used: Python 3.7 in Spyder
  • Presentation app: Microsoft’s PowerPoint
  • Presentation shown to spark ideas of use.
  • This presentation is not connected to or endorsed by any company.
  • Use at your own risk.
  • Tags: Python, Python3.7, Multiprocess, Multiprocessing, Lock, Multiple UUT one DMM, Parallelism, Parallel, Run one function many times in parallel, one function in Multiprocessing needs Lock, Lock need some time to Lock, Multiple UUT Testing slot with same test, Queues

About LV_TS_Test_Engineer_3000_VI

Automated Test Equipment Software
This entry was posted in Test Sector and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s