User avatar
Gavinmc42
Posts: 4020
Joined: Wed Aug 28, 2013 3:31 am

Re: How to utilize output from one program in another

Fri Nov 29, 2019 4:00 am

Hi Gavin, was this meant for me?
If it helps, yes, otherwise just ignore me.
I only spotted this post yesterday.

You are using time.sleep in Python?
100% cpu usage?
I don't like loops in Python, bad experience years ago.
If I need to use Python I make sure it exits and call it via shell script etc
I run free when testing Python code to make sure there are no memory leaks.

It has been years since I used Python for GPIO stuff, tend to use Joan's pigpio daemon.
Most of my stuff tend to run 24/7 so it needs to work well.
Stuff that is just UI on/off then Python is okish.

I have toggled GPIO pins from one program to signal another app in another language.
Not as silly as writing a 0 or 1 to file on the uSD ;)
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

koenner
Posts: 14
Joined: Mon Nov 02, 2015 5:53 am

Re: How to utilize output from one program in another

Sat Nov 30, 2019 4:42 am

I am really new to this, programming in general, so Python is all I know, but seems like a good one to start with given all the available support.

RE: time.sleep and 100% CPU usage, what would you recommend? Just to give some background, this machine would only ever be tasked with this program.

Isn't this a fair way to exit?

Code: Select all

except KeyboardInterrupt:
    sys.exit()
The machine/program will be used in a manufacturing type environment, and the operator will have limited experience therefore the super basic run and exit.

koenner
Posts: 14
Joined: Mon Nov 02, 2015 5:53 am

Re: How to utilize output from one program in another

Tue Dec 03, 2019 6:11 am

Gavinmc42 wrote:
Fri Nov 29, 2019 4:00 am
Hi Gavin, was this meant for me?
If it helps, yes, otherwise just ignore me.
I only spotted this post yesterday.

You are using time.sleep in Python?
100% cpu usage?
I don't like loops in Python, bad experience years ago.
If I need to use Python I make sure it exits and call it via shell script etc
I run free when testing Python code to make sure there are no memory leaks.

It has been years since I used Python for GPIO stuff, tend to use Joan's pigpio daemon.
Most of my stuff tend to run 24/7 so it needs to work well.
Stuff that is just UI on/off then Python is okish.

I have toggled GPIO pins from one program to signal another app in another language.
Not as silly as writing a 0 or 1 to file on the uSD ;)

Hi Gavin,

You're right. I ran this code with my hardware (Pi 2 with breadboard linked to designated pins), and seems it cannot exit the example.py program. Any ideas? Once the program enters example.py it seems to just stay there; even using Keyboard Interrupt seems non-functional!! I ended up using Ctrl+C to exit, but even that seemed to take some time.

User avatar
Gavinmc42
Posts: 4020
Joined: Wed Aug 28, 2013 3:31 am

Re: How to utilize output from one program in another

Tue Dec 03, 2019 7:28 am

Have a look at Joan's code, it has Python examples.
http://abyz.me.uk/rpi/pigpio/
My GPIO handling days are Wheezy old, not sure how it works these days.
Seem to remember a daemon (pigpiod) ran in background and handled things.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

koenner
Posts: 14
Joined: Mon Nov 02, 2015 5:53 am

Re: How to utilize output from one program in another

Wed Dec 04, 2019 7:05 am

Gavinmc42 wrote:
Tue Dec 03, 2019 7:28 am
Have a look at Joan's code, it has Python examples.
http://abyz.me.uk/rpi/pigpio/
My GPIO handling days are Wheezy old, not sure how it works these days.
Seem to remember a daemon (pigpiod) ran in background and handled things.
Thanks it seems pretty comprehensive. I'll need to go in deeper this weekend to find what I'm looking for. Perhaps if I ask you a question in a conceptual way you might be able to help me answer it in the meantime though. If I setup Module A in a specific way within Program A, and later in the program call on Module B, which also has Module A embedded, but is setup in a different way, will the setup from Module A be retained, or overwritten?

This may be a really silly question/concept to ask, but would be very helpful to understand how the program is read. It would help me to understand if I need to go into the subsequent modules (example.py and HX711.py) and update the way that the GPIO pins are defined to be consistent with my "master" program (biggy.py), or if my settings in biggy.py will be maintained regardless of whatever is written later.

I realize this is pretty conceptual, and if it's too vague to answer that's fine, but if you do have any insights would appreciate them none the less!

User avatar
Gavinmc42
Posts: 4020
Joined: Wed Aug 28, 2013 3:31 am

Re: How to utilize output from one program in another

Wed Dec 04, 2019 11:32 am

I don't think I have run multiple python apps at the same time.
That might need a google.I do have 4 versions of Python 2.6, 3.5, 3.6, 3.7.
So I suppose it is possible to run all four interpreters at the same time, perhaps even on different cores?

example.py and HX711.py are two programs that get interpreted by the Python engine.
If it was examples.sh and HX711 then it is the Bash shell and Python shell, two separate programs running at the same time.

You can have one python xxx.py that imports the others.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Return to “Beginners”