943,724 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 1273
  • Python RSS
Sep 23rd, 2009
0

help with threads and obexftp push

Expand Post »
Hello all,

I recently started using Python to test a Bluetooth Push application prototype and everything was working great until threading. I wonder if someone knows how to start multiple threads of connectpush() with Obexftp running under Linux?
So far with the code below I have to wait until the first client connection gets close to start the next connection and I need to start many push connections at once.

The strange part is that the threads are working for obexftp.browsebt() method so I get push channels in every
thread or maybe it's because we don't need to accept or deny a connection to read a push channel in a Bluetooth device.

Thank you for your help
Luis S.

Python Syntax (Toggle Plain Text)
  1. import time
  2. import obexftp
  3. import threading
  4.  
  5. def discover():
  6. cli = obexftp.client(obexftp.BLUETOOTH)
  7. clientes = cli.discover()
  8. radios = len(clientes)
  9. cli.disconnect()
  10. cli.delete
  11. return clientes
  12.  
  13. class pushfile(threading.Thread):
  14. def __init__(self,mac):
  15. threading.Thread.__init__(self)
  16. self.mac = mac
  17.  
  18. def run(self):
  19. cli = obexftp.client(obexftp.BLUETOOTH)
  20. canal = obexftp.browsebt(self.mac,obexftp.PUSH)
  21. time.sleep(1)
  22. print "Connected to push channel: ",canal," of: ",self.mac
  23. time.sleep(1)
  24.  
  25. cli.connectpush(self.mac,canal,'hci2')
  26. print "Sending file to: %s" % self.mac
  27. enviado = cli.put_file("filename.jpg")
  28. if enviado == 1:
  29. print "Send to: %s" % self.mac
  30. cli.disconnect()
  31. cli.delete
  32. time.sleep(1)
  33.  
  34. start = time.time()
  35. devicelist = []
  36.  
  37. dispositivos = discover()
  38. radios = len(dispositivos)
  39. print dispositivos
  40. print radios
  41.  
  42. for i in range(radios):
  43. mac = dispositivos[i]
  44. t = pushfile(mac)
  45. devicelist.append(t)
  46. t.start()
  47.  
  48. for push in devicelist:
  49. push.join()
  50. print "Thread ended for: ",push.mac
  51.  
  52. print "Elapsed Time: %s" % (time.time() - start)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
luiss is offline Offline
1 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: a simple math problem
Next Thread in Python Forum Timeline: My first oop project - can my code be simplified?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC