[Buildbot-devel] BuildStep: Calling a function repeatedly until it returns correct value
Edward Ekelund
edward.ekelund at axis.com
Tue Nov 20 12:26:04 UTC 2012
Hello,
During a certain step in the build process I need to call on an external
python method that will query a server for an ip address matching
certain criteria. Let's call it get_ip(criteria).
get_ip() will either return the ip address or a flag indicating that all
addresses matching the criteria are currently busy.
If all addresses are busy I don't want the current step to continue -- I
want it to poll get_ip(criteria) every x minutes until an ip becomes
available and thus can be returned.
My first naive approach was to set up a polling method and call it
instead, i.e:
def poll_ip(interval, matching_criteria):
ip = get_ip(matching_criteria)
if ip == "busy":
time.sleep(interval)
ip = get_ip(matching_criteria)
return ip
This doesn't work at all. In fact, the call to time.sleep() locks the
whole buildbot process so that nothing can be done until get_ip stops
returning busy. Not even the web-gui is working. Not good.
I realize I will have to utilize twisted somehow to call get_ip()
asynchronously, and repeatedly if necessary. I am new to asynchronous
programming and twisted, and none of my feeble attempts have worked,
however.
I feel it shouldn't be that difficult. Does anyone here know of a good
solution to my problem?
Thanks,
Eddie
More information about the devel
mailing list