-1

Hi stackoverflow users,

my question is quite straigtforward:

How can I use a variable in the name of another command?

My Script looks roughly like this:

    for i in range(1, face_recognition_core_count+1):
    face_finder+i = multiprocessing.Process(target=find_faces, args=(total_frame_count, i))
    face_finder+i.start()
    face_finder+i.join()
marcr
  • 9
  • 3

1 Answers1

0

Use a dictionary.

face_finder_dict = {}
for i in range(1, face_recognition_core_count + 1):
    face_finder_dict[f"face_finder{i}"] = multiprocessing.Process(target=find_faces, args=(total_frame_count, i))
    face_finder_dict[f"face_finder{i}"].start()
    face_finder_dict[f"face_finder{i}"].join()
Tweakimp
  • 393
  • 5
  • 16
  • @marcr I edited the code to use a string name. I thought you had defined face_finder in your example code in the original post. – Tweakimp Nov 17 '19 at 17:51
  • Hi, this also doesn't seem to works, because the started Process has the same name. So it will only create one Process named face_finder_dict and the other ones will have the same name and cannot be created. – marcr Nov 17 '19 at 17:53
  • the first process will be the value of face_finder_dict[f"face_finder0"], the second one the value of face_finder_dict[f"face_finder1"] and so on. why do they have the same name? – Tweakimp Nov 17 '19 at 17:56
  • I think python ignores the [...] on .start and .join. I dont know how to bypass this. – marcr Nov 17 '19 at 17:57
  • Ah, I found the problem. I first need to define all of the Multiprocessing functions and only after that start them. – marcr Nov 17 '19 at 17:59