When I attempt to connect to a bluetooth device in a separate thread in python i get a whole bunch of Cocoa errors. Is this PyObjc related or something to do with lightblue?
[bt] 2008-06-21 20:25:28,734 DEBUG Creating socket
[bt] 2008-06-21 20:25:28,734 DEBUG Connecting
2008-06-21 20:25:28.738 Python[10641:2703] *** _NSAutoreleaseNoPool(): Object 0x53462e0 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x909bdcdf 0x908ca562 0x908d59ba 0x55de205 0x55c3e47 0x55c1ff2 0x4082855 0x4082d6c 0x4099825 0x40b0b63 0x11fd3d 0x18db1a 0x18d9e8 0x18d9e8 0x18d9e8 0x18f45b 0x139c27 0x11fd3d 0x1285f8 0x11fd3d 0x188b15 0x1b5a2d 0x9606b6f5 0x9606b5b2)
2008-06-21 20:25:28.739 Python[10641:2703] *** _NSAutoreleaseNoPool(): Object 0x5347d70 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x909bdcdf 0x908ca562 0x908d59ba 0x55de205 0x55f8580 0x55f888f 0x55c4432 0x55c451a 0x55c2031 0x4082855 0x4082d6c 0x4099825 0x40b0b63 0x11fd3d 0x18db1a 0x18d9e8 0x18d9e8 0x18d9e8 0x18f45b 0x139c27 0x11fd3d 0x1285f8 0x11fd3d 0x188b15 0x1b5a2d 0x9606b6f5 0x9606b5b2)
2008-06-21 20:25:28.742 Python[10641:2703] *** _NSAutoreleaseNoPool(): Object 0x5348820 of class NSCFData autoreleased with no pool in place - just leaking
Stack: (0x909bdcdf 0x908ca562 0x908dec35 0x908de811 0x90905c8d 0x90905b38 0x9094e26a 0x55ca7c6 0x55c4cb5 0x55c4461 0x55c451a 0x55c2031 0x4082855 0x4082d6c 0x4099825 0x40b0b63 0x11fd3d 0x18db1a 0x18d9e8 0x18d9e8 0x18d9e8 0x18f45b 0x139c27 0x11fd3d 0x1285f8 0x11fd3d 0x188b15 0x1b5a2d 0x9606b6f5 0x9606b5b2)
...
Thanks,
Brant
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've gotten rid of the allocation errors by allocating a separate NSAutoreleasePool in the thread. I can see the connection going through, but the code hangs on the recv() call.
I've put a little example code here.
Thanks for any help!
Example code follows:
import logging
import time
import binascii
import threading
import Foundation
class BTCom():
def __init__(self):
self.device_bt_addr = '00:07:80:82:38:0E'
def start_client(self):
try:
logging.debug("Connecting")
result = self.sock.connect((self.device_bt_addr,1))
logging.debug("Entering read loop")
self.read_loop(self.sock)
except Exception:
logging.error("Exception connecting to device")
raise
finally:
self.sock.close()
def read_loop(self,sock):
while(True):
val = sock.recv(1)
print binascii.hexlify(val)
class BTComThread(threading.Thread):
def __init__(self,btc):
threading.Thread.__init__(self)
self.btc = btc
def run(self):
pool = Foundation.NSAutoreleasePool.alloc().init()
logging.debug("Initing client socket")
self.btc.init_client_socket()
logging.debug("Starting client")
self.btc.start_client()
del pool
if '__main__' == __name__:
bt = BTCom()
t = BTComThread(bt)
t.start()
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't know the exact cause of the hang on recv(), but IOBluetooth (the underlying Bluetooth framework on Mac OS X) doesn't actually support multithreading. So unfortunately you can't actually do it this way.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all,
When I attempt to connect to a bluetooth device in a separate thread in python i get a whole bunch of Cocoa errors. Is this PyObjc related or something to do with lightblue?
[bt] 2008-06-21 20:25:28,734 DEBUG Creating socket
[bt] 2008-06-21 20:25:28,734 DEBUG Connecting
2008-06-21 20:25:28.738 Python[10641:2703] *** _NSAutoreleaseNoPool(): Object 0x53462e0 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x909bdcdf 0x908ca562 0x908d59ba 0x55de205 0x55c3e47 0x55c1ff2 0x4082855 0x4082d6c 0x4099825 0x40b0b63 0x11fd3d 0x18db1a 0x18d9e8 0x18d9e8 0x18d9e8 0x18f45b 0x139c27 0x11fd3d 0x1285f8 0x11fd3d 0x188b15 0x1b5a2d 0x9606b6f5 0x9606b5b2)
2008-06-21 20:25:28.739 Python[10641:2703] *** _NSAutoreleaseNoPool(): Object 0x5347d70 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x909bdcdf 0x908ca562 0x908d59ba 0x55de205 0x55f8580 0x55f888f 0x55c4432 0x55c451a 0x55c2031 0x4082855 0x4082d6c 0x4099825 0x40b0b63 0x11fd3d 0x18db1a 0x18d9e8 0x18d9e8 0x18d9e8 0x18f45b 0x139c27 0x11fd3d 0x1285f8 0x11fd3d 0x188b15 0x1b5a2d 0x9606b6f5 0x9606b5b2)
2008-06-21 20:25:28.742 Python[10641:2703] *** _NSAutoreleaseNoPool(): Object 0x5348820 of class NSCFData autoreleased with no pool in place - just leaking
Stack: (0x909bdcdf 0x908ca562 0x908dec35 0x908de811 0x90905c8d 0x90905b38 0x9094e26a 0x55ca7c6 0x55c4cb5 0x55c4461 0x55c451a 0x55c2031 0x4082855 0x4082d6c 0x4099825 0x40b0b63 0x11fd3d 0x18db1a 0x18d9e8 0x18d9e8 0x18d9e8 0x18f45b 0x139c27 0x11fd3d 0x1285f8 0x11fd3d 0x188b15 0x1b5a2d 0x9606b6f5 0x9606b5b2)
...
Thanks,
Brant
I've gotten rid of the allocation errors by allocating a separate NSAutoreleasePool in the thread. I can see the connection going through, but the code hangs on the recv() call.
I've put a little example code here.
Thanks for any help!
Example code follows:
import logging
import time
import binascii
import threading
import Foundation
class BTCom():
def __init__(self):
self.device_bt_addr = '00:07:80:82:38:0E'
def init_client_socket(self):
import lightblue
self.sock = lightblue.socket()
def start_client(self):
try:
logging.debug("Connecting")
result = self.sock.connect((self.device_bt_addr,1))
logging.debug("Entering read loop")
self.read_loop(self.sock)
except Exception:
logging.error("Exception connecting to device")
raise
finally:
self.sock.close()
def read_loop(self,sock):
while(True):
val = sock.recv(1)
print binascii.hexlify(val)
class BTComThread(threading.Thread):
def __init__(self,btc):
threading.Thread.__init__(self)
self.btc = btc
def run(self):
pool = Foundation.NSAutoreleasePool.alloc().init()
logging.debug("Initing client socket")
self.btc.init_client_socket()
logging.debug("Starting client")
self.btc.start_client()
del pool
if '__main__' == __name__:
bt = BTCom()
t = BTComThread(bt)
t.start()
I don't know the exact cause of the hang on recv(), but IOBluetooth (the underlying Bluetooth framework on Mac OS X) doesn't actually support multithreading. So unfortunately you can't actually do it this way.
Thanks for the reply. Should have RTFM more closely