Giter Site home page Giter Site logo

Comments (5)

diezm avatar diezm commented on August 24, 2024 1

Thanks for your reply. I

Either create different InstantCameras in each process ( although only one have to have the camera "open" at any time )

I tried this, but it also did not work.

The problem described above only occurs when the program structure is like this:

Main Process
.... do some stuff ....
open camera
read params
close camera
       start subprocess
       open camera

I found a workaround by starting a subprocess just to read out the camera params now, this works

Main Process
.... do some stuff ....

      start subprocess_1
      open camera
      read params
      close cam
      kill subprocess

      start subprocess_2
      open camera
      start streaming 

from pypylon.

thiesmoeller avatar thiesmoeller commented on August 24, 2024

your code will try to transfer the InstantCamera between processes.

 def __new__(cls):
        if cls._instance is None:
            cls._instance = super(Basler, cls).__new__(cls)
            cls._instance.camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
            cls._instance.is_streaming = Value('b', False)
        return cls._instance

The communication in python multiprocessing is via pickling/unpickling of objects between the processes. This doesn't work and would be extremely inefficient for the InstantCamera.

Either create different InstantCameras in each process ( although only one have to have the camera "open" at any time )
Or by adding additional methods to set/get parameters or a list of parameters from the other process.
The objects transferred have to be pure python.

In #513 (comment) I gave an example how to run pypylon in one process and transfer video data to other process via shared memory to be efficient.

from pypylon.

jonahpearl avatar jonahpearl commented on August 24, 2024

We had the same issue -- your fix resolved it for us. Would still like to understand the root cause so we can avoid it!

EDIT: it appears to be an issue with multiprocessing using spawn instead of fork on Linux. The problem wasn't present on Windows, and we solved it equally well with:

current_mp_start_method = mp.get_start_method()
if current_mp_start_method != "spawn":
    mp.set_start_method("spawn", force=True)

from pypylon.

thiesmoeller avatar thiesmoeller commented on August 24, 2024

The root cause is described in #714 (comment).

You have to centralize the camera access ( InstantCamera) in one process.
The object can't move between processes.

Best practice is linked in the above comment. Only process the data in sub processes.
This can be optimized by using shared memory for the image data

from pypylon.

jonahpearl avatar jonahpearl commented on August 24, 2024

Ok — I think I'm experiencing a slightly distinct problem that is better described in #659 — going to take this over there.

from pypylon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.