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

interupt prpblems #8

Open
martynwheeler opened this issue Jul 26, 2013 · 10 comments
Open

interupt prpblems #8

martynwheeler opened this issue Jul 26, 2013 · 10 comments

Comments

@martynwheeler
Copy link

I have a fresh install on my Pi and I cannot get the interupt code working i run
sudo python3 presslights.py

it just sits there and doesn't respond to switch presses. I have tried other example code and I get nothing on any of the interupts that I've tried.

I have no idea what the problem is, eventually i press ctrl-x-c and get

^X^CException KeyboardInterrupt: KeyboardInterrupt() in <module 'threading' from '/usr/lib/python3.2/threading.py'> ignored
Process Process-1:
Traceback (most recent call last):
File "/usr/lib/python3.2/multiprocessing/process.py", line 267, in _bootstrap
self.run()
File "/usr/lib/python3.2/multiprocessing/process.py", line 116, in run
self._target(_self._args, *_self._kwargs)
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/interrupts.py", line 160, in watch_port_events
events = epoll.poll()
KeyboardInterrupt

Please help as I've just bought 5 pi faces for some school projects.

Thanks
Martyn

@martynwheeler
Copy link
Author

I may have found the solution, I rebooted and ran the program again without sudo. This seemed to make it work! However, it still doesn't exit cleanly on Ctrl-C.

@tompreston
Copy link
Member

It's up to you how you handle keyboard interrupts. Maybe this can help? :-)

@HakanL
Copy link

HakanL commented Sep 20, 2013

Is there a better way to properly close down the thread that watches interrupts? It seems that hiding the keyboard interrupt isn't the best way.

@tompreston
Copy link
Member

@HakanL I'm not quite sure what you mean.

To deactivate the listener (and close down the associated processes) you call the deactivate() method of the listener:

listener = pifacedigitalio.InputEventListener()
listener.activate()
listener.deactivate()

http://piface.github.io/pifacedigitalio/example.html#interrupts

Or are you referring to the stackoverflow link I posted above?

@HakanL
Copy link

HakanL commented Sep 20, 2013

It's probably due to my novice experience with Python, but in my application I have a main function that pumps events and I have a try/catch for KeyboardInterrupt with pass in there. Then the code just runs out of scope. But I get the stack trace on the console with KeyboardInterrupt and one of the stacks is from PiFace. I'm sorry I didn't post the trace, I'll try to do that this weekend (not at home with my Pi now). Here's my code: https://github.com/HakanL/animatroller/blob/master/RaspExpander/RaspExpander.py

@tompreston
Copy link
Member

Perhaps the KeyboardInterrupt is being sent to all processes* and you're letting it reach the listener. Try deactivating the listener in your exception handler:

except KeyboardInterrupt:
        print ('Aborting')
        pfd_listener.deactivate()
else:
        pfd_listener.deactivate()
        print ('Done')

If not, the stack trace would be useful. :-)

*The interrupt watcher runs in a separate process because Python can't do real threads

@HakanL
Copy link

HakanL commented Sep 23, 2013

I tried that, didn't seem to help. Here's the stack trace:

Input value 1 on channel 4
Input value 0 on channel 4
^CAborting
Process Process-1:
Traceback (most recent call last):
  File "/usr/lib/python3.2/multiprocessing/process.py", line 267, in _bootstrap
Done
    self.run()
  File "/usr/lib/python3.2/multiprocessing/process.py", line 116, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3/dist-packages/pifacecommon/interrupts.py", line 166, in watch_port_events
    events = epoll.poll()
KeyboardInterrupt
Goodbye

@tompreston
Copy link
Member

I've pushed what I think is a fix to the testing branches in pifacecommon v4.0.0 and pifacedigitalio v2.1.1.

Would you mind downloading those and testing them using your code, please?

@tompreston tompreston reopened this Sep 23, 2013
@HakanL
Copy link

HakanL commented Sep 24, 2013

I'm still getting a call-stack, but it's slightly different now:

Input value 0 on channel 4
^CAborting
Process Process-1:
Traceback (most recent call last):
  File "/usr/lib/python3.2/multiprocessing/process.py", line 267, in _bootstrap
    self.run()
  File "/usr/lib/python3.2/multiprocessing/process.py", line 116, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.2/dist-packages/pifacecommon/interrupts.py", line 222, in watch_port_events
    events = epoll.poll()
IOError: [Errno 4] Interrupted system call
Done
Goodbye

Not sure I installed the updated libraries correctly (I'm still green on Python). I did a git clone/checkout of testing, then python3 setup.py build, followed by install, first on command and then digitalio. Is that it?

@tompreston
Copy link
Member

You installed it correctly (although, you don't have to run build, Python will do that for you when you run install). Notice how your library is in /usr/local/lib/ and not /usr/lib/. /usr/lib/ is where main Debian packages are installed and /usr/local/lib/ is the default place to do things without Aptitude (python3 setup.py install). You can check this on the fly by looking at the __file__ magic variable of the module:

import pifacedigitalio
print(pifacedigitalio.__file__)

Python will look in /usr/local/lib first. Be careful of this when you decide that you want to go back to your main modules. You will have to delete the /usr/local/lib versions manually since python3 setup.py doesn't have an uninstall.

As for your stack trace, it appears that the "Interrupted system call" can be ignored though I don't really like that solution. Does the error happen every time you close? Can you replicate the error without your full program (just a very basic program that you can kill with Ctrl+C).

I've pushed a possible fix in the dev_thomas_preston branch which ignores the Interrupted system call error. Please make sure that your program isn't the cause before testing this branch. I'll get around to testing it myself later in the day/week but whatever you can do would be really helpful!

Thanks

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