Ankündigung

Einklappen
Keine Ankündigung bisher.

python - thread error

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • python - thread error

    Hi,

    I have following code to check the presence/absence of an LE bluetooth device.
    I keep on getting following error:
    Code:
    Exception in thread Thread-2:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
        self.run()
      File "/usr/lib/python2.7/threading.py", line 763, in run
        self.__target(*self.__args, **self.__kwargs)
      File "check_beacon_presence.py", line 48, in SendUdp
        sock.sendto(sent_data, ("xxx.xxx.x.xxx", xxxx))
    TypeError: function takes exactly 1 argument (2 given)
    What I understand from searching the internet is that you can not pass a string into the thread. It has to be a "tulen"?
    So what I did was: placind message between []. An other solution would be placing a "," after message without [], but also this does not work.
    Code:
    threadReqAway = threading.Thread(target=SendUdp, args=([message]))
    Code:
    ## function for sending udp to loxone miniserver
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    def SendUdp(sent_data):
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        sock.sendto(sent_data, ("xxx.xxx.x.xxx", xxxx))    
    ## end function udp sending
    message = "0"
    
    class CheckAbsenceThread(threading.Thread):
        def __init__(self):
            threading.Thread.__init__(self)
        def run(self):
    
            time.sleep(ABSENCE_FREQUENCY)    
            for tag in TAG_DATA:
                elapsed_time_absence=time.time()-tag[3]
                if elapsed_time_absence>=tag[2] : # sleep execute after the first Home check.
                    #logging.warning('Tag %s not seen since %i sec => update absence',tag[0],elapsed_time_absence)
                    message = "AFWEZIG_"+tag[0]
                    #print message
                    #SendUdp(message)
                    threadReqAway = threading.Thread(target=SendUdp, args=([message]))
                    threadReqAway.start()
                    #sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
                    #sock.sendto(sent_data, ("xxx.xxx.x.xxx", xxxx))
    Anyone any advice?

  • #2
    Some more information:

    I grabbed the code from the internet.

    I replaced
    Code:
    def request_thread(idx,cmd, name):
        try:
            url = URL_DOMOTICZ
            url=url.replace('PARAM_IDX',str(idx))
            url=url.replace('PARAM_CMD',str(cmd))
            url=url.replace('PARAM_NAME',str(name))
            result = requests.get(url,auth=(DOMOTICZ_USER, DOMOTICZ_PASS))
            logging.debug(" %s -> %s" % (threading.current_thread(), result))
        except requests.ConnectionError, e:
            logging.critical(' %s Request Failed %s - %s' % (threading.current_thread(), e, url) )
    by
    Code:
    ## function for sending udp to loxone miniserver
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    def SendUdp(sent_data):
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        sock.sendto(sent_data, ("xxx.xxx.x.xxx", xxxx))    
    ## end function udp sending
    message = "0"
    and replaced
    Code:
    threadReqAway = threading.Thread(target=request_thread,args=(tag[4],"AWAY",tag[0]))
                    threadReqAway.start()
    by

    Code:
    threadReqAway = threading.Thread(target=SendUdp, args=([message]))
                    threadReqAway.start()
    And since then I get the error....

    Kommentar

    Lädt...
    X