python thread prob after build

Posted by Apache on Stack Overflow See other posts from Stack Overflow or by Apache
Published on 2010-04-30T04:27:08Z Indexed on 2010/04/30 4:37 UTC
Read the original article Hit count: 344

Filed under:
|
|

hi expert, i'm having task to scan wifi at specific interval and send it to the server, i've it in python and its works fine when i run manually, then build it to package and when run there is no progress at all, i already ask this question before at http://stackoverflow.com/questions/2735410/python-scritp-problem-once-build-and-package-it,

then, i re-modify my code as below, then i found that thread is not functioning once i build,

#!/usr/bin/env python
import subprocess,threading,...

configFile = open('/opt/Jemapoh_Wifi/config.txt', 'r')
url = configFile.readline().strip()
intervalTime = configFile.readline().strip()
status = configFile.readline().strip()
print "url "+url
print "intervalTime "+intervalTime
print "Status "+status.strip()

def getMacAddress():
        proc = subprocess.Popen('ifconfig -a wlan0 | grep HWaddr |  sed \'/^.*HWaddr */!d; s///;q\'', shell=True, stdout=subprocess.PIPE, )
        macAddress = proc.communicate()[0].strip()
        return macAddress

def getTimestamp():
        from time import strftime
        timeStamp = strftime("%Y-%m-%d %H:%M:%S")
        return timeStamp        

def scanWifi():
       try:
        print "Scanning..."
        proc = subprocess.Popen('iwlist scan 2>/dev/null', shell=True, stdout=subprocess.PIPE, )
        stdout_str = proc.communicate()[0]
        stdout_list=stdout_str.split('\n')

        essid=[]
        rssi=[]
        preQuality=[]

        for line in stdout_list:
            line=line.strip()

            match=re.search('ESSID:"(\S+)"',line)
            if match:
            essid.append(match.group(1))

            match=re.search('Quality=(\S+)',line) 
            if match:
            preQuality.append(match.group(1))

        for qualityConversion in preQuality:
            qualityConversion = qualityConversion.split()[0].split('/')
            temp = str(int(round(float(qualityConversion[0]) / float(qualityConversion[1]) * 100))).rjust(2)
            rssi.append(temp)

        dataToPost = '{"userId":"' + getMacAddress() + '","timestamp":"' + getTimestamp() + '","wifi":['

        for no in range(len(essid)):
            dataToPost += '{"ssid":"' + essid[no] + '","rssi":"' + rssi[no] + '"}'
            if no+1 == len(essid):
                pass
            else:
                dataToPost += ','
        dataToPost += ']}'

        query_args = {"data":dataToPost}
        request = urllib2.Request(url)
        request.add_data(urllib.urlencode(query_args))
        request.add_header('Content-Type', 'application/x-www-form-urlencoded')

        print "Waiting for server response..."
        print urllib2.urlopen(request).read()
        print "Data Sent @ " + getTimestamp()
        print "------------------------------------------------------"
        t = threading.Timer(int(intervalTime), scanWifi).start()

       except Exception, e:
        print e

t = threading.Timer(int(intervalTime), scanWifi)
t.start()

once build, its not reaching the thread, do can anyone help, why the thread is not working after build

thanks

© Stack Overflow or respective owner

Related posts about python

Related posts about threading