Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some question about Multi-threading #231

Open
mihudaner opened this issue Jul 24, 2023 · 9 comments
Open

some question about Multi-threading #231

mihudaner opened this issue Jul 24, 2023 · 9 comments

Comments

@mihudaner
Copy link

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?

@eskaur
Copy link
Member

eskaur commented Jul 24, 2023

Which version of zivid-python are you using? (pip show zivid)

@mihudaner
Copy link
Author

mihudaner commented Jul 24, 2023

image

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()

@mihudaner
Copy link
Author

When capturing, the interface of my pyqt will also become very stiff, but I have already placed it in a sub thread for execution

@eskaur
Copy link
Member

eskaur commented Jul 24, 2023

Aha, actually there is no released version of zivid-python that supports multithreading.
We recently fixed this on master branch: #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.

@mihudaner
Copy link
Author

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

@eskaur
Copy link
Member

eskaur commented Jul 24, 2023

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: #222

@mihudaner
Copy link
Author

mihudaner commented Jul 24, 2023

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

@eskaur
Copy link
Member

eskaur commented Jul 24, 2023

I mean, the lower version can use threading, right?

You mean if 2.8.0.2.9.0 can use threading? Sorry, no :)

@mihudaner
Copy link
Author

I understand. Thank you again (my English is not very good (●'◡'●))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants