Python not recognizing multiprocessing semaphore in other file -


i have 3 different files in project, main.py, generator.py , multiplicator.py. it's program multiply 2 matrix using phyton multiprocessing module. i've created semaphores in main file:

from multiprocessing import process, semaphore, queue, cpu_count,  value, manager random import randrange generator import * multiplicator import *  mutex_mult = semaphore(1) sem_generator = semaphore(1) 

and i'm trying use mutex_mult lock queue in init of multiplicator process (i python has own mutex, it's programming exercise).

from main import *  class multiplicator(process):     def __init__(self, rows_matrix_1, matrix_2, queue, row_start):         process.__init__(self)         self.queue = queue         mutex_mult.acquire()         self.matrix_final = queue.get()         queue.put(self.matrix_final)         mutex_mult.release()         self.rows_matrix_1 = rows_matrix_1         self.matrix_2 = matrix_2         self.row_start = row_start 

but when call in main initializer multiplicator,

traceback (most recent call last):   file "/users/luccaportes/pycharmprojects/multiplicator_matrix/main.py", line 54, in <module>     m = multiplicator(matrix_1, matrix_2, queue,0)   file "/users/luccaportes/pycharmprojects/multiplicator_matrix/multiplicator.py", line 7, in __init__     mutex_mult.acquire() nameerror: name 'mutex_mult' not defined 

but if call exact same command in generator process, works fine.

how can solve this?


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -