Hi chaps,
We're looking to upgrade from 1.4.5 to 1.9.4 in order to benefit from some of the Python core 2.5.2 functionality, but in doing so some of the socket behaviour in our code has broken. Here are the relevant code snippets (apologies if the indentation formatting gets broken) .
We import the btsocket module as:
and instantiate a socket via:Code:import btsocket as socket
Data packets are then read via calls to the function:Code:sock = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
We also register a Disconnect function via the atexit module for when we terminate the application, which has the form:Code:def receivePacket(sock): buffer = "" packetComplete = False while not packetComplete : try: ch = sock.recv(1) except: print "error communicating with sensor" continue # loop until packet received while(ch != '\n'): buffer += ch try: ch = sock.recv(1) except: print "error communicating with sensor" continue packetComplete = True return buffer
Now with 1.4.5 everything stops working cleanly when Disconnect is invoked, but with 1.9.4 the diagnostic string "error communicating with sensor" gets echoed (doesn't happen with 1.4.5) and the whole phone freezes up. Only rebooting the phone is then possible. Why does the thread of execution return to the receivePacket function in 1.9.4 when the function registered with atexit has been invoked? Is this a bug in 1.9.4?Code:def Disconnect(): global sock, # Close the Bluetooth socket sock.close() # other code removed
Regards,
m

Reply With Quote


