я хочу отправить файл многократным устройства одновременно с помощью питона ... мой код:отправить файл многократным устройства одновременно с помощью питона и BlueZ
import bluetooth
from lightblue import *
import select
import threading
def send(fileaddress,bladdress,pushport):
client = obex.OBEXClient(bladdress, pushport)
client.connect()
client.put({"name": "test"}, open(fileaddress))
def StartSend(fileaddress,bladdress,pushport):
t=threading.Thread(group=None,target=send, name=None, args=(fileaddress,bladdress,pushport))
t.daemon=True
t.start()
t.join()
class MyDiscoverer(bluetooth.DeviceDiscoverer):
def pre_inquiry(self):
self.done = False
def device_discovered(self, addr, device_class, name):
print "%s - %s" % (addr, name)
serv = bluetooth.find_service(name="OBEX Object Push", uuid=None, address=None)
pushport = serv[0]['port']
StartSend('/home/abbas/Desktop/eclipse-standard-kepler-SR2-linux-gtk.tar.gz', addr, pushport)
def inquiry_complete(self):
self.done = True
if __name__ == '__main__':
d = MyDiscoverer()
d.find_devices(lookup_names = True)
readfiles = [ d, ]
while True:
rfds = select.select(readfiles, [], [])[0]
if d in rfds:
d.process_event()
if d.done: break
но когда первое устройство обнаружения и начать посылать файл к этому все скрипт python приостановился и дождался, что отправка финиша и последующее начало отправки другого устройства ...
Почему?
Я использую thread, поэтому зачем приостановить процесс python на этапе отправки?
я использовать этот сайт для них код: http://people.csail.mit.edu/albert/bluez-intro/x339.html
To asynchronously detect nearby bluetooth devices, create a subclass of DeviceDiscoverer and override the pre_inquiry, device_discovered, and inquiry_complete methods. To start the discovery process, invoke find_devices, which returns immediately. pre_inquiry is called immediately before the actual inquiry process begins, and inquiry_complete is called as soon as the process completes.
MyDiscoverer exposes a fileno method, which allows it to be used with the select module. This provides a way for a single thread of control to wait for events on many open files at once, and greatly simplifies event-driven programs.
Call process_event to have the DeviceDiscoverer process pending events, which can be either a discovered device or the inquiry completion. When a nearby device is detected, device_discovered is invoked, with the address and device class of the detected device. If lookup_names was set in the call to find_devices, then name will also be set to the user-friendly name of the device. For more information about device classes