1

In a program I am writing, I have a small problem. I would like to be able to know when an element has been created but do not have access to the element's library. The library provides a function that returns True or False when it is finished and ready to continue. Currently I am using a busy wait structure such as:

    def Waiting_Procedure():
        finished = false
        while not finished:
            time.sleep(1)
            if library_function_returns_true:
                finished = true

This works fine for now, but I'd like to know if there is a better/simpler/elegant way to accomplish this in Python. Also, if the library never returns true, it would spin forever at 1 second intervals, which would not be ideal.

Thanks!

NAlex
  • 11
  • 2
  • Without specifics, it's difficult to help. Does the library provide a Python object ? If so, is that completion signal from the library available as an object attribute instead of from a function call? – dilbert Apr 16 '14 at 03:02
  • Hi dilbert, the library provides a Python object but it has a limited set of public members (center, height, width, x, and y). The _myObject.library_function_returns_true()_ is the only public method available and let's you know if the element has been created/found. I apologize if I have been a bit vague – NAlex Apr 16 '14 at 04:12
  • Thanks NAlex. Unfortunately, this probably means that you will have to continue with the polling (busy-waiting) approach. Do you have access to the source of the library ? Perhaps there are other features you could exploit. – dilbert Apr 16 '14 at 05:45
  • 1
    Well it looks like I didn't RTFM in depth enough, there was a function wait_until() which essentially does what I wanted to do, but internally. Thank you for your help. – NAlex Apr 16 '14 at 21:54

1 Answers1

0

Disclaimer: I'm the developer of busypie

I would also suggest you either develop a better busy waiting mechanism or use a ready made one (like busypie) which will give you more option including timeout and error handling (so it will not loop forever in any case)

eli segal
  • 11
  • 1