← Back to team overview

sikuli-driver team mailing list archive

Re: [Bug 1204634] Re: [1.0] Find fail after use it for a long time

 

Well, this is the waiter, it is not completed, it should be better if is
static, or a singleton class, need some refactors, but is the main idea, be
carefull publishing the code, because I dont have enough privilegies to
share it.

class WaitUntilNoChangesInRegion(object):
    """
    This class is responsible for wait until no visual changes are detected
in a given Region.
    """
    DEFAULT_CHANGE_POLLING_INTERVAL = 0.5
    DEFAULT_MINIMUM_CHANGED_SIZE = 500
    DEFAULT_OBSERVE_TIME_FRAME = 3
    DEFAULT_MAXIMUM_WAIT_TIME = 15
    DEFAULT_OBSERVE_SCAN_RATE = 2

    def __init__(self, change_polling_interval =
DEFAULT_CHANGE_POLLING_INTERVAL,
                 min_changed_size = DEFAULT_MINIMUM_CHANGED_SIZE,
                 observe_time_frame = DEFAULT_OBSERVE_TIME_FRAME,
                 max_wait_time = DEFAULT_MAXIMUM_WAIT_TIME,
                 observe_scan_rate = DEFAULT_OBSERVE_SCAN_RATE):
        """
        Initializer method.

        Receives configuration values to control the time used to wait
while changes occur,
        and the minimum size of a visual change in the region.

        Parameters:
            change_polling_interval - Maximum time to wait between visual
change
            in the given region.
            min_changed_size - Minimum amount of pixels that the observe
event catch.
            observe_time_frame - Maximum amount of seconds to wait without
changes.
            max_wait_time - Maximum total time for the class to observe the
region.
            observe_scan_rate - Times per second the observer check for
changes.
        """
        self.set_wait_change_polling_interval(change_polling_interval)
        self.set_minimum_changed_size(min_changed_size)
        self.set_observe_time_frame(observe_time_frame)
        self.set_maximum_wait_time(max_wait_time)
        self.set_observe_scan_rate(observe_scan_rate)

    def wait_while_changes_occur(self, region_to_observe = Region(SCREEN),
change_observe_time_frame = None):
        """
        Receives the Region to observe and wait until no changes in the
region appear.

        Parameters:
            region_to_observe - Region expected to change, optional,
default value SCREEN.
            change_observe_time_frame - Maximum amount of seconds to wait
without changes, useful only one time,
            if is None the default value defined in the initializer is used.
        """
        self.region = is_paf_region(region_to_observe)
        self._is_still_changing = True
        self.total_time = 0
        self.region.onChange(self.minimum_changed_size,
self._observe_change)

        with WaitUntilNoChangesContextConfigurator(self, self.region,
change_observe_time_frame):
            self._start_observer()
            self.region.stopObserver()

    def _start_observer(self):
        """
        Private method, this method starts the observer and enters into a
loop
        until no more changes happen in the region.
        """
        self.start_time = time.time()

        while (self._is_still_changing is True and self.total_time <
self.maximum_wait_time):
            self._is_still_changing = False
            self.observer_start_time = time.time()
            self.region.observe(self.observe_time_frame, background = False)
            self._wait_between_events()

        if (self.total_time >= self.maximum_wait_time and
self._is_still_changing is True):
            self.region.take_screenshot("The region is still changing.")
            logger.warn("The application is still changing after the
maximum wait time of %s seconds"\
                        % self.maximum_wait_time)

    def _observe_change(self, event):
        """
        Private method, observe event listener function, it is invoked when
the observe
        event is triggered.

        Parameters:
            event - Event object with information about the visual change.
        """
        event.region.stopObserver()
        self._is_still_changing = True

    def _wait_between_events(self):
        """
        Private method, it uses for wait between visual events.
        """
        self.total_time = time.time() - self.start_time

        if (self._is_still_changing is True):
            wait(self.wait_change_polling_interval)
        else:
            last_observe_time = time.time() - self.observer_start_time
            logger.debug("No more changes were detected after %s seconds.
Total wait time: %s"\
                         % (last_observe_time, self.total_time))

    def set_wait_change_polling_interval(self, value):
        """
        Setter to verify and assign the value to
wait_change_polling_interval.

        Parameters:
            value - Value for wait_change_polling_interval.
        """
        self.wait_change_polling_interval = as_float(value)

    def set_minimum_changed_size(self, value):
        """
        Setter to verify and assign the value to minimum_changed_size.

        Parameters:
            value - Value for minimum_changed_size.
        """
        self.minimum_changed_size = as_int(value)

    def set_observe_time_frame(self, value):
        """
        Setter to verify and assign the value to observe_time_frame.

        Parameters:
            value - Value for observe_time_frame.
        """
        self.observe_time_frame = as_float(value)

    def set_maximum_wait_time(self, value):
        """
        Setter to verify and assign the value to maximum_wait_time.

        Parameters:
            value - Value for maximum_wait_time.
        """
        self.maximum_wait_time = as_float(value)

    def set_observe_scan_rate(self, value):
        """
        Setter to verify and assign the value to observe_scan_rate.

        Parameters:
            value - Value for observe_scan_rate.
        """
        self.observe_scan_rate = as_float(value)


2014-01-12 11:36 GMT-04:00 RaiMan <rmhdevelop@xxxxxx>:

> ** Changed in: sikuli
>     Milestone: 1.1.0 => 1.2.0
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1204634
>
> Title:
>   [1.0] Find fail after use it for a long time
>
> Status in Sikuli:
>   In Progress
>
> Bug description:
>   Version: Sikuly finally 1.0.0
>   OS: Windows 7 64-bits
>   Reproduce: Execute find operations for a long period of time.
>
>   When I use the find operation (or others than use find inside) on a
>   automatized scenario during long periods of time, the find operation
>   fail in some point, if I try to find the image again is found but in a
>   long execution it fails, and not always the same image fail.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/sikuli/+bug/1204634/+subscriptions
>

-- 
You received this bug notification because you are a member of Sikuli
Drivers, which is subscribed to Sikuli.
https://bugs.launchpad.net/bugs/1204634

Title:
  [1.0] Find fail after use it for a long time

Status in Sikuli:
  In Progress

Bug description:
  Version: Sikuly finally 1.0.0
  OS: Windows 7 64-bits
  Reproduce: Execute find operations for a long period of time.

  When I use the find operation (or others than use find inside) on a
  automatized scenario during long periods of time, the find operation
  fail in some point, if I try to find the image again is found but in a
  long execution it fails, and not always the same image fail.

To manage notifications about this bug go to:
https://bugs.launchpad.net/sikuli/+bug/1204634/+subscriptions


References