Python code able to run in terminal but not after boot up

Moderators: mdrjr, odroid

Python code able to run in terminal but not after boot up

Unread postby yihhern » Mon Jul 23, 2018 12:47 pm

I have a python code which starts up with a text to speech, followed by audio recording. Based on the audio data collected and after analysis, there will be two possible text to speech outcome. Example ("detected" and " not detected"). The python code runs in a while loop, constantly recording audio and displaying the text to speech outcome. The python code works perfectly fine in the terminal but when the code is executed during boot up, it only runs until the first text to speech. I have tried crontab and rc.local and both had the same problem. I am using ODROID C0 with OS Ubuntu 16.04.3 mate odroid c1 20170908 installed V2.2.

What can i do to execute the whole python code during boot up?

Thanks
Last edited by yihhern on Fri Jul 27, 2018 11:21 am, edited 1 time in total.
yihhern
 
Posts: 5
Joined: Mon Jul 23, 2018 12:21 pm
languages_spoken: english
ODROIDs: ODROID C0

Re: Python code able to run in terminal but not after boot u

Unread postby mad_ady » Mon Jul 23, 2018 1:10 pm

Most likely your code tries to run some system command which is not in PATH when run from cron or boot. I recommend you prefix all system commands with their absolute path.
Otherwise it might depend on pulseaudio which usually starts when the user logs in.
You should try to capture error output to a file on startup (2>/tmp/error.log).
User avatar
mad_ady
 
Posts: 4717
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: Python code able to run in terminal but not after boot u

Unread postby yihhern » Mon Jul 23, 2018 4:03 pm

How do i prefix all the system commands with their absolute path?
yihhern
 
Posts: 5
Joined: Mon Jul 23, 2018 12:21 pm
languages_spoken: english
ODROIDs: ODROID C0

Re: Python code able to run in terminal but not after boot u

Unread postby mad_ady » Mon Jul 23, 2018 4:12 pm

E.g. instead of running find, run /usr/bin/find. You can find out the path of a command from a shell with which find.
Typically paths within /sbin, /usr/sbin, /usr/local/bin, /usr/local/sbin are not in the system default PATH so programs within will not be found without a little help.
User avatar
mad_ady
 
Posts: 4717
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: Python code able to run in terminal but not after boot u

Unread postby yihhern » Mon Jul 23, 2018 4:42 pm

For the text to speech , i am using espeak. I have included the directory, so instead of espeak i changed it into /usr/bin/espeak. The code still runs perfectly fine in the terminal but only runs the first text to speech during boot up.
yihhern
 
Posts: 5
Joined: Mon Jul 23, 2018 12:21 pm
languages_spoken: english
ODROIDs: ODROID C0

Re: Python code able to run in terminal but not after boot u

Unread postby mad_ady » Mon Jul 23, 2018 4:55 pm

In this case you need to log the output of your code - it might fail due to some other dependency. Also, when calling espeak, pipe the STDERR to a file so you can catch any errors it might have. I suspect the sound isn't initialized at that point and it dies. Are you using pulseaudio for playback? You may need something like this (look for the pulseaudio section): viewtopic.php?t=27661
User avatar
mad_ady
 
Posts: 4717
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1

Re: Python code able to run in terminal but not after boot u

Unread postby yihhern » Mon Jul 23, 2018 5:43 pm

I am using a C-Media USB Headphone Set. I use a microphone for input(Audio Adapter Analog Mono) and speaker for output(Audio Adapter Analog Stereo). I am using Pyaudio for the audio recording. There is only recording and no playback in the code. When i run the code in the command line, it shows
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

and then proceeds to record and based on the data output either "detected" or "not detected".
I have changed to default sound card 1 ( C-Media USB Headphone Set). So it should be using the microphone and speaker plugged in the C-Media USB Headphone Set for input and output.
yihhern
 
Posts: 5
Joined: Mon Jul 23, 2018 12:21 pm
languages_spoken: english
ODROIDs: ODROID C0

Re: Python code able to run in terminal but not after boot u

Unread postby yihhern » Wed Jul 25, 2018 3:48 pm

mad_ady thanks for helping me out. I managed to solve the problem by executing the python code in the terminal after boot up with the start up application. In start up application, click Add. Give any name you want.Under command, type mate-terminal -e "python3 /home/odroid/script.py" . It looks like my python code needed the terminal for it to run. I also found out that the jack server is not running or cannot be started.... is a information to let user know that the portaudio is unable to locate the jack server and this is not an error. Once again, thanks so much for helping me @mad_ady .
yihhern
 
Posts: 5
Joined: Mon Jul 23, 2018 12:21 pm
languages_spoken: english
ODROIDs: ODROID C0

Re: Python code able to run in terminal but not after boot u

Unread postby mad_ady » Wed Jul 25, 2018 6:54 pm

Yes, in that case the script inherits your environment
User avatar
mad_ady
 
Posts: 4717
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2, N1


Return to Issues

Who is online

Users browsing this forum: No registered users and 1 guest