Re: [Dorset] Python Function Appears to be Entered Twice

2017-03-14 Thread Terry Coles
On Tuesday, 14 March 2017 18:38:37 GMT Ralph Corderoy wrote:
> OK, though I think it's a software problem.  Out of interest, what kind
> of cabling and runs are we talking?

It is plain wire and it was about 40 cm from the switches to the pull-downs 
board (via a D-Type).  Then there is about 4 to 5 cm between the resistors and 
the GPIO pins.  The capacitors (0,1 uF) are connected across each switch 
contact.

> > pi@raspberrypi:~/WMT/Code/Minster_Functions $ sudo strace -tt -o
> > strace.out -f \> 
> > > -e trace=process -e trace=file -e trace=desc \
> > > 
> > > changerings3.py
> > 
> > strace: Can't stat 'changerings3.py': No such file or directory
> 
> File changerings3.py isn't in the current directory.

But it was.  The path in the prompt matches the one below that was found, but 
wouldn't execute.  Also, I used tab completion to confirm that I'd got the 
right filename.

> Success!  It found the file, but it isn't executable.

Why?  I didn't do anything special to your example and that did execute, so 
why won't mine?  However, after I made my file executable strace worked.

So I say again, how come yours worked when I didn't make it executable? !!

(I've never made any of my Python files executable because I usually launch 
them from within IDLE or by executing:

python myfile.py

(This may well have changed by the time I get round to deploying this software 
to launch at boot-up.)
 
> I think even if changerings3.py was made executable, it would still have
> problems because it's running env(1) with `python 2.7' as arguments, and
> that would run python(1), which might be version 2 or 3, and pass it
> `2.7 /home/terry/WMT/Code/Minster_Functions/changerings3.py'.  It
> wouldn't like 2.7 as the script to run.

No.  It did work.
 
> sudo strace -tt -o strace.out -f \
> -e trace=process -e trace=file -e trace=desc \
> python2.7 test-callback.py

See http://www.hadrian-way.co.uk/Misc/strace.out

-- 



Terry Coles

-- 
Next meeting:  Bournemouth, Tuesday, 2017-04-04 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR


Re: [Dorset] Python Function Appears to be Entered Twice

2017-03-14 Thread Ralph Corderoy
Hi Terry,

> so I only got onto all this again this afternoon.

No need to explain.  I'm used to email threads having days between
posts.  :-)

> Clive has shortened the cabling considerably and we've removed the
> outer plastic sheath and teased out the wires on all of the cable runs
> to reduce the cross-talk to a minimum.

OK, though I think it's a software problem.  Out of interest, what kind
of cabling and runs are we talking?

> /usr/lib/python3/dist-packages/RPi.GPIO-0.6.3.egg-info
> This ties in with the version in the Raspbian Package Manager.

And the latest tar file of source I could find on the SourceForge site.

> I've put the complete script, cut-down as you suggested, in:
>   http://www.hadrian-way.co.uk/Misc/changerings3.py.txt

Very handy, thanks.

> > sudo strace -tt -o strace.out -f \
> > -e trace=process -e trace=file -e trace=desc \
> > your-python-script.py
>
> pi@raspberrypi:~/WMT/Code/Minster_Functions $ sudo strace -tt -o 
> strace.out -f \
> > -e trace=process -e trace=file -e trace=desc \
> > changerings3.py 
> strace: Can't stat 'changerings3.py': No such file or directory

File changerings3.py isn't in the current directory.

> pi@raspberrypi:~/WMT/Code/Minster_Functions $ sudo strace -tt -o 
> strace.out -f -e trace=process -e trace=file -e trace=desc changerings3.py
> strace: Can't stat 'changerings3.py': No such file or directory

Ditto.  (Though you have removed the backslashes correctly.)

> pi@raspberrypi:~/WMT/Code/Minster_Functions $ sudo strace -tt -o 
> strace.out -f -e trace=process -e trace=file -e trace=desc 
> ~/WMT/Code/Minster_Functions/changerings3.py
> strace: exec: Permission denied

Success!  It found the file, but it isn't executable.

> pi@raspberrypi:~/WMT/Code/Minster_Functions $ sudo strace -tt -o 
> strace.out -f \
> > -e trace=process -e trace=file -e trace=desc \changerings3.py 
> strace: Can't stat 'changerings3.py': No such file or directory

Now you're guessing.  :-)  That still looks for file
`./changerings3.py'.

I think even if changerings3.py was made executable, it would still have
problems because it's running env(1) with `python 2.7' as arguments, and
that would run python(1), which might be version 2 or 3, and pass it
`2.7 /home/terry/WMT/Code/Minster_Functions/changerings3.py'.  It
wouldn't like 2.7 as the script to run.

And when the script is run, it sets up the GPIO requirements and then
exits.  There's nothing to make the main thread hang around whilst your
dalliance with the GPIO thread occurs.

Here's your test script with even more lines deleted.  It should run
with

python2.7 test-callback.py

without needing to make it executable.  Hopefully, you can exhibit the
problem with it.  Then trigger the problem again under strace.

sudo strace -tt -o strace.out -f \
-e trace=process -e trace=file -e trace=desc \
python2.7 test-callback.py

 8<  cut here 
#! /usr/bin/env python2.7

import time
import RPi.GPIO as GPIO

def main():
print GPIO.VERSION

GPIO.setmode(GPIO.BCM) # Pin numbering scheme.
for pin in (22,):
GPIO.setup(pin, GPIO.IN)
GPIO.add_event_detect(pin, GPIO.RISING, callback=handle_event, 
bouncetime=300)

print 'main sleeping'
time.sleep(42)
print 'main done'

def handle_event(gpio):
print 'enter', gpio
time.sleep(3)
print 'exit', gpio

main()
 8<  cut here 

Cheers, Ralph.

-- 
Next meeting:  Bournemouth, Tuesday, 2017-04-04 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR


Re: [Dorset] Python Function Appears to be Entered Twice

2017-03-14 Thread Terry Coles
On Tuesday, 14 March 2017 17:21:12 GMT Stephen Wolff wrote:
> >> What's the line look like that registers your callback?
> > 
> > I've put the complete script, cut-down as you suggested, in:
> > http://www.hadrian-way.co.uk/Misc/changerings3.py.txt
> > 
> >> Taking the stripped down, simple as possible, test program, have it do
> >> the time.sleep(2) and not import the subprocess module.  Run it under
> >> strace(1) to capture its interactions with the kernel.  (The Python
> >> module is a poorly documented black box there to provide a "helpful"
> >> abstraction; we're now trying to see through it to understand its
> >> behaviour.  :-)
> >> 
> >> sudo strace -tt -o strace.out -f \
> >> 
> >> -e trace=process -e trace=file -e trace=desc \
> >> your-python-script.py
> 
> Can you put the ‘add_switch_events()’ under an if __name__ == ‘main’:
> 
> see
> 
>  - http://stackoverflow.com/questions/4041238/why-use-def-main
> 
> could it be that the script is called each time the file is imported?

So I rewrote the last line of the script as:

if __name__ == '__main__':
add_switch_events()

but the code didn't do anything!

-- 



Terry Coles
-- 
Next meeting:  Bournemouth, Tuesday, 2017-04-04 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR


Re: [Dorset] Python Function Appears to be Entered Twice

2017-03-14 Thread Stephen Wolff

>> What's the line look like that registers your callback?
>
> I've put the complete script, cut-down as you suggested, in:
>
>   http://www.hadrian-way.co.uk/Misc/changerings3.py.txt
>
>> Taking the stripped down, simple as possible, test program, have it do
>> the time.sleep(2) and not import the subprocess module.  Run it under
>> strace(1) to capture its interactions with the kernel.  (The Python
>> module is a poorly documented black box there to provide a "helpful"
>> abstraction; we're now trying to see through it to understand its
>> behaviour.  :-)
>>
>> sudo strace -tt -o strace.out -f \
>> -e trace=process -e trace=file -e trace=desc \
>> your-python-script.py
>

Can you put the ‘add_switch_events()’ under an if __name__ == ‘main’:

see

 - http://stackoverflow.com/questions/4041238/why-use-def-main

could it be that the script is called each time the file is imported?
-- 
Next meeting:  Bournemouth, Tuesday, 2017-04-04 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR


Re: [Dorset] Python Function Appears to be Entered Twice

2017-03-14 Thread Terry Coles
Ralph,

It's been a while since you wrote.  Yesterday was model town day + shopping 
and this morning, I had other errands to run. so I only got onto all this 
again this afternoon.

In the meantime, Clive has shortened the cabling considerably and we've 
removed the outer plastic sheath and teased out the wires on all of the cable 
runs to reduce the cross-talk to a minimum.

I monitored the 'Change Runs On'  GPIO pin with my (fairly limited) Arduino 
based scope and saw a little bounce when the switch was depressed (less than 1 
ms) and no bounce when it was released (as you would expect).  Of course, a 
very fast edge or ringing wouldn't show up on that scope, although I have been 
offered the loan of a real one, if it would help. 

On Sunday, 12 March 2017 18:10:45 GMT Ralph Corderoy wrote:
> What version is the GPIO Python module you're using?  If it's not
> obvious, then there may be a GPIO.VERSION string that can be printed
> from Python.

pi@raspberrypi:~ $ find /usr/ | grep -i RPi.GPIO
/usr/share/doc/python-rpi.gpio



/usr/lib/python3/dist-packages/RPi.GPIO-0.6.3.egg-info




This ties in with the version in the Raspbian Package Manager.

> What's the line look like that registers your callback?

I've put the complete script, cut-down as you suggested, in:

http://www.hadrian-way.co.uk/Misc/changerings3.py.txt

> Taking the stripped down, simple as possible, test program, have it do
> the time.sleep(2) and not import the subprocess module.  Run it under
> strace(1) to capture its interactions with the kernel.  (The Python
> module is a poorly documented black box there to provide a "helpful"
> abstraction; we're now trying to see through it to understand its
> behaviour.  :-)
> 
> sudo strace -tt -o strace.out -f \
> -e trace=process -e trace=file -e trace=desc \
> your-python-script.py

I couldn't get that to work.  See what I tried:

 pi@raspberrypi:~/WMT/Code/Minster_Functions $ sudo strace -tt -o strace.out -
f \> -e trace=process -e trace=file -e trace=desc \
> changerings3.py 
strace: Can't stat 'changerings3.py': No such file or directory
pi@raspberrypi:~/WMT/Code/Minster_Functions $ sudo strace -tt -o strace.out -f 
-e trace=process -e trace=file -e trace=desc changerings3.py
strace: Can't stat 'changerings3.py': No such file or directory
pi@raspberrypi:~/WMT/Code/Minster_Functions $ sudo strace -tt -o strace.out -f 
-e trace=process -e trace=file -e trace=desc ~/WMT/Code/Minster_Functions/
changerings3.py
strace: exec: Permission denied
pi@raspberrypi:~/WMT/Code/Minster_Functions $ sudo strace -tt -o strace.out -f 
\
> -e trace=process -e trace=file -e trace=desc \changerings3.py 
strace: Can't stat 'changerings3.py': No such file or directory

I'm not sure why it can't find the script; I used tab completion to get the 
name right.

-- 



Terry Coles

-- 
Next meeting:  Bournemouth, Tuesday, 2017-04-04 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread:  mailto:dorset@mailman.lug.org.uk / CHECK IF YOU'RE REPLYING
Reporting bugs well:  http://goo.gl/4Xue / TO THE LIST OR THE AUTHOR