Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过python&;同时向多个设备发送文件;布鲁兹_Python - Fatal编程技术网

通过python&;同时向多个设备发送文件;布鲁兹

通过python&;同时向多个设备发送文件;布鲁兹,python,Python,我想通过python同时向多个设备发送一个文件。。。 我的代码: 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"}

我想通过python同时向多个设备发送一个文件。。。 我的代码:

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脚本都暂停并等待发送完成,然后下一次开始发送另一个设备

为什么?

我使用线程,为什么要在发送步骤中暂停python进程

我使用此网站进行以下代码:


问题是
StartSend
函数加入线程,等待线程完成。因此,创建线程是毫无意义的。尝试改用
多处理.ThreadPool
。它没有很好的文档记录,但其工作原理与
多处理.Pool
相同

 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