pypylon
pypylon copied to clipboard
Can't call GetInstance methods in other processes once they have been used in the main process
It seems like using any pylon.TlFactory.GetInstance()
method works fine in other processes until any of those methods are used within the main process, after which all the methods cause the code to hang. Is there a way to get around this? Is there maybe a way to close the instance allowing for it to be called in other processes? Here is an example code:
from multiprocessing import Process
from pypylon import pylon
import time
def get_device_infos(id):
print(f'processing {id} starting')
pylon.TlFactory.GetInstance().EnumerateDevices()
print(f'Processing {id} complete')
# calling EnumerateDevice (or any GetInstance method) is a process is ok
p1 = Process(target=get_device_infos, args=(1,))
p2 = Process(target=get_device_infos, args=(2,))
p1.start()
p2.start()
time.sleep(1)
print()
# Once EnumerateDevice (or any GetInstance method) is called in the
# main process then it no longer works in other process
pylon.TlFactory.GetInstance().CreateFirstDevice()
p3 = Process(target=get_device_infos, args=(3,))
p3.start()
# Hangs here forever