Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to use timeout #492

Open
xav12358 opened this issue Jul 19, 2022 · 4 comments
Open

Try to use timeout #492

xav12358 opened this issue Jul 19, 2022 · 4 comments

Comments

@xav12358
Copy link

xav12358 commented Jul 19, 2022

Hello,
I try to use connect function with a timeout. I use bluepy in 1.3.0 and it seems there is no timeout argument.

Si I try to design a timeout with multithread and queue.

Here is my code:


       #####################################"
        # def connection_worker(ret_status_queue, new_num_list_in):
        def connection_worker(ret_status_queue, ret_service_queue):

            try:
                self.peripheral.connect(ble_mac_address)
                time.sleep(0.1)
                service = self.peripheral.getServiceByUUID(self.SERVICE_UUID)
                characteristic = service.getCharacteristics()[0]
                ret_characteristic_queue.put(characteristic )
                ret_status_queue.put("OK")
            except Exception as err:
                print('errin {}'.format(err))
                ret_status_queue.put("NOK")
                ret_status_queue.task_done()

        ret_status_queue = multiprocessing.Queue()
        ret_characteristic_queue = multiprocessing.Queue()
        # proc = multiprocessing.Process(target=connection_worker, args=(ret_status_queue,new_num_list))
        proc = multiprocessing.Process(target=connection_worker, args=(ret_status_queue,ret_characteristic_queue))
        proc.start()
        try:
            ret_value = ret_status_queue.get(timeout=22)
        except Exception as err:
            ret_value = 'NOK'
        proc.terminate()

        if ret_value == 'OK':
            # Get characteristic
            try:
                characteristic = ret_service_queue.get(timeout=5) // Not good characterictic
                self.characteristic = characteristic
            except Exception as err:
                print('holala {}'.format(err))

What is the proper way to set a timeout function on connection?

I try many thing, because the service or the characteristic doesn't seems to be usable outside the thread.

@maciej-napora
Copy link

maciej-napora commented Jul 19, 2022 via email

@maciej-napora
Copy link

maciej-napora commented Jul 19, 2022 via email

@xav12358
Copy link
Author

When should a new tag generate to integrate that modification?

@maciej-napora
Copy link

My feeling is that this should take a while, as there is not much action happening here. You can always download the most recent code from this repo and call it from your application, instead of the lib installed by PIP. That's what I have been doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants