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

Unable to KeyboardInterrupt when ImageAcquirer exists #463

Open
4 of 6 tasks
zamzz opened this issue Jun 20, 2024 · 2 comments
Open
4 of 6 tasks

Unable to KeyboardInterrupt when ImageAcquirer exists #463

zamzz opened this issue Jun 20, 2024 · 2 comments

Comments

@zamzz
Copy link

zamzz commented Jun 20, 2024

Describe the Issue
Keyboard Interrupt / Ctrl+C isn't being caught/acknowledged when an ImageAcquirer is in existence. Interesting that quit() instead of Ctrl+C works for me.

Sample Code
I can show a piece of code that demonstrates the reported phenomenon:

  • Yes
  • No

If yes, please provide a sample code:

Stops on KeyboardInterrupt once "waiting!" starts printing:

import time
from harvesters.core import Harvester


if __name__ == "__main__":
    h = Harvester()
    h.add_file("")  # insert producer path here
    h.update()

#    with h.create() as ia:
#        pass
    
    while True:
        print("waiting!")
        time.sleep(1)

Doesn't stop on KeyboardInterrupt once "waiting!" starts printing:

import time
from harvesters.core import Harvester


if __name__ == "__main__":
    h = Harvester()
    h.add_file("")  # insert producer path here
    h.update()

    with h.create() as ia:
        pass
    
    while True:
        print("waiting!")
        time.sleep(1)

Expected Behavior

Configuration

  • OS: Ubuntu 22.04
  • Python: 3.8
  • Harvester: 1.4.3

Reproducibility

This phenomenon can be stably reproduced:

  • Yes
  • No.

If applicable, please provide your observation about the reproducibility.
I'm unsure if this happens with other cameras (or producers to be honest).

Actions You Have Taken

@KABILAN235
Copy link

I've got the same problem too and haven't found a solution yet

@basfee
Copy link

basfee commented Aug 21, 2024

Came across the same issue. I looked into it. Creation of the ImageAcquirer object registers a handler for SIGINT. It seems that this overrides the default handler that normally raises the KeyboardInterrupt.

See

signal.signal(signal.SIGINT, self._sigint_handler)

Looks like it is used to destroy the ImageAcquisition object. Potential workaround (I'm not sure if this is ideal) is to register your own handler again and raising KeyboardInterrupt. If you do this after ImageAcquisition object is created, it will override that one again..

import time
import signal
from harvesters.core import Harvester


if __name__ == "__main__":
    h = Harvester()
    h.add_file("")  # insert producer path here
    h.update()

    with h.create() as ia:
        pass

    def sigint_handler(self, frame):
        raise KeyboardInterrupt
    signal.signal(signal.SIGINT, sigint_handler)
    
    while True:
        print("waiting!")
        time.sleep(1)

Perhaps you could call ImageAcquisition its handler from your own handler to keep Harvester behave the same ?

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

No branches or pull requests

3 participants