niespielak
Posts: 11
Joined: Fri Aug 22, 2014 11:37 am

Python3 script doesn't finish

Fri Aug 22, 2014 11:43 am

Hello Everyone,
I made script to record temperature readout into mysql database. If I use simple command:
"Python3 Temperatura.py" everything is ok - script finish and I have record in database, but when I try to use:
"./Temepratura" or "sudo ./Temperatura" script starts and is still working - I have to use Ctrl-c (script doesn't made any record in database. I thin it is problem connected with header of the script - someone help?

Scirpt code is under:

#! /usr/bin/env python3

import os
import glob
import mysql.connector

nazwaKontroleraTemp = "'RaspXBMC'"
connectionsql = mysql.connector.connect(user='raspberry', password='*********',host='10.0.0.80',database='home_rasp')

os.system('sudo modprobe w1-gpio')
os.system('sudo modprobe w1-therm')

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'

def odczytajtemperature_surowy():
f = open(device_file, 'r')
lines = f.readlines()
f.close()
return lines

def odczytajtemperature():
lines = odczytajtemperature_surowy()
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
return temp_c
kursor = connectionsql.cursor()
temperatura = odczytajtemperature()
insert_temperatura = ("INSERT INTO Temperatura "
"(Termometr, Data, Odczyt)"
" VALUES (%s , now() , %s )")
dane_temperatura = (nazwaKontroleraTemp,temperatura)
kursor.execute(insert_temperatura,dane_temperatura)

kursor.close()
connectionsql.commit()
connectionsql.close()

riklaunim
Posts: 265
Joined: Tue Apr 22, 2014 7:34 pm

Re: Python3 script doesn't finish

Fri Aug 22, 2014 3:52 pm

Put debug print('something') statements between lines you suspect that are the cause of this and find on which line the script stops execution.

niespielak
Posts: 11
Joined: Fri Aug 22, 2014 11:37 am

Re: Python3 script doesn't finish

Fri Aug 22, 2014 10:03 pm

I think there in not any execution of the python script - it isn't start anyway! I put print as You said in the first line after the script header "#! /usr/bin/env python3" and there is no answer on the bash screen. I think problem is connected with bash excecutin of python script. As I mention in first post if I use in bash "Python3 Termometr.py" script works, it isn't if try to execute using "./Termometr.py" - nothin happens.

User avatar
joan
Posts: 14553
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Python3 script doesn't finish

Fri Aug 22, 2014 10:07 pm

Are you being accurate with your typing?

Linux is case sensitive.

Python3 != python3

niespielak
Posts: 11
Joined: Fri Aug 22, 2014 11:37 am

Re: Python3 script doesn't finish

Fri Aug 22, 2014 10:13 pm

Yep i know that :) I check out that in path and python3 is good in my statement.

Return to “Troubleshooting”