my code fragment:
Code:
	
	def __init__(self):
		self.lok = thread.allocate_lock()

        def connect(self):
		self.lok.acquire()

		self.sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
		address=('00:1f:81:00:01:00',3) #(addr,port)
                print "connecting...."
		self.sock.connect(address)
		self.rep = self.sock.makefile("rw", 0)
		print "OK."

		self.lok.release()

	def receive(self):
            r = self.rep.read(1)

        d = App()
	thread.start_new_thread(d.connect, ())
	thread.start_new_thread(d.receive, ())

my objective is to first execute connect() completely, and then execute receive(), through threads.

but when this program is run, it first prints "connecting....", then receive() is executed. so i get an error at self.rep.read(1) - self.rep is None object. and strangely, after showing the error, and triggering an io error in the server, "ok" from connect() gets printed.