some question about Multi-threading
When I was developing using Python, I didn't want to block opening the camera or collecting data, so I placed the connection camera in a sub thread. However, I don't know why, the entire process is blocked, so connecting the camera shouldn't take up a lot of resources, right? But why is the entire process blocked?
Which version of zivid-python are you using? (pip show zivid)
this is my easy test demo with threading belowed Running the connection camera print hi on my computer will be blocked
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023/7/20 7:13
# @Author : mihudan~
# @File : test_load_zivid.py
# @Description :
import time
import zivid
import threading
def print_hi():
while True:
time.sleep(0.01)
print(f'Hi, ')
if __name__ == '__main__':
t1 = threading.Thread(target=zivid.Application().connect_camera)
t2 = threading.Thread(target=print_hi)
t2.start()
time.sleep(3)
t1.start()
t2.join()
When capturing, the interface of my pyqt will also become very stiff, but I have already placed it in a sub thread for execution
Aha, actually there is no released version of zivid-python that supports multithreading. We recently fixed this on master branch: https://github.com/zivid/zivid-python/pull/222
So you have two options now:
- Install zivid-python from repo source (instructions in readme file).
- Wait a week or two for SDK 2.10.0 to be released, then install official zivid-python for that.
So the lower version is compatible, right? I would also like to know the underlying cause of this bug, as I happen to be learning about multithreading and multiprocessing. Why does this thread affect other threads? I want to ask for some adviceO(∩_∩)O
So the lower version is compatible, right?
Not sure what you mean. The latest version on PyPI is 2.9.0.2.9.0, and that one does not include the fix. However, it is fixed on master branch so you could install pre-release by checking out the git repository and installing from that.
As to why it failed: The issue is that we would apply the Global Interpreter Lock ("GIL") whenever some work was passed to the Zivid SDK. This locks all threads. See here for more details: https://github.com/zivid/zivid-python/pull/222
Not sure what you mean
I mean, the lower version can use threading, right? /
As to why it failed: The issue is that we would apply the Global Interpreter Lock ("GIL") .......
thank you very much indeed
I mean, the lower version can use threading, right?
You mean if 2.8.0.2.9.0 can use threading? Sorry, no :)
I understand. Thank you again (my English is not very good (●'◡'●))