How to use the eventlet.sleep function in eventlet

To help you get started, we’ve selected a few eventlet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / swift / test / unit / __init__.py View on Github external
self.sent = 0
            self.received = 0
            self.etag = etag
            self.body = body
            self.headers = headers or {}
            self.expect_headers = expect_headers or {}
            self.timestamp = timestamp
            self.connection_id = connection_id
            self.give_send = give_send
            if 'slow' in kwargs and isinstance(kwargs['slow'], list):
                try:
                    self._next_sleep = kwargs['slow'].pop(0)
                except IndexError:
                    self._next_sleep = None
            # be nice to trixy bits with node_iter's
            eventlet.sleep()
github openstack / swift / test / unit / obj / test_server.py View on Github external
resp = req.get_response(self.object_controller)
            self.assertEquals(resp.status_int, 204)
            objfile = os.path.join(
                self.testdir, 'sda1',
                storage_directory(diskfile.DATADIR, 'p',
                                  hash_path('a', 'c', 'o')),
                timestamp + '.ts')
            self.assert_(os.path.isfile(objfile))
            self.assertEquals(1, calls_made[0])
            self.assertEquals(len(os.listdir(os.path.dirname(objfile))), 1)

            # The following request should return a 404, as the object should
            # already have been deleted, but it should have also performed a
            # container update because the timestamp is newer, and a tombstone
            # file should also exist with this timestamp.
            sleep(.00001)
            timestamp = normalize_timestamp(time())
            req = Request.blank('/sda1/p/a/c/o',
                                environ={'REQUEST_METHOD': 'DELETE'},
                                headers={'X-Timestamp': timestamp})
            resp = req.get_response(self.object_controller)
            self.assertEquals(resp.status_int, 404)
            objfile = os.path.join(
                self.testdir, 'sda1',
                storage_directory(diskfile.DATADIR, 'p',
                                  hash_path('a', 'c', 'o')),
                timestamp + '.ts')
            self.assert_(os.path.isfile(objfile))
            self.assertEquals(2, calls_made[0])
            self.assertEquals(len(os.listdir(os.path.dirname(objfile))), 1)

            # The following request should return a 404, as the object should
github jwkvam / bowtie / bowtie / _cache.py View on Github external
value : object
            The value to store in the cache.

        Returns
        -------
        None

        """
        validate(key)
        signal = 'cache_save'
        if flask.has_request_context():
            emit(signal, {'key': pack(key), 'data': pack(value)})
        else:
            sio = flask.current_app.extensions['socketio']
            sio.emit(signal, {'key': pack(key), 'data': pack(value)})
        eventlet.sleep()
github eventlet / eventlet / eventlet / green / subprocess.py View on Github external
def wait(self, timeout=None, check_interval=0.01):
        # Instead of a blocking OS call, this version of wait() uses logic
        # borrowed from the eventlet 0.2 processes.Process.wait() method.
        if timeout is not None:
            endtime = time.time() + timeout
        try:
            while True:
                status = self.poll()
                if status is not None:
                    return status
                if timeout is not None and time.time() > endtime:
                    raise TimeoutExpired(self.args, timeout)
                eventlet.sleep(check_interval)
        except OSError as e:
            if e.errno == errno.ECHILD:
                # no child process, this happens if the child process
                # already died and has been cleaned up
                return -1
            else:
                raise
    wait.__doc__ = subprocess_orig.Popen.wait.__doc__
github jwkvam / bowtie / bowtie / _component.py View on Github external
def actualcommand(self, *args, **kwds):  # pylint: disable=missing-docstring
        data = command(self, *args, **kwds)
        name = command.__name__[3:]
        signal = '{uuid}{sep}{event}'.format(
            uuid=self._uuid, sep=SEPARATOR, event=name  # pylint: disable=protected-access
        )
        if flask.has_request_context():
            emit(signal, {'data': pack(data)})
        else:
            sio = flask.current_app.extensions['socketio']
            sio.emit(signal, {'data': pack(data)})
        eventlet.sleep()
github openstack / swift / swift / common / utils.py View on Github external
# 1,000 milliseconds = 1 second
    clock_accuracy = 1000.0

    # Convert seconds to milliseconds
    now = time.time() * clock_accuracy

    # Calculate time per request in milliseconds
    time_per_request = clock_accuracy * (float(incr_by) / max_rate)

    # Convert rate_buffer to milliseconds and compare
    if now - running_time > rate_buffer * clock_accuracy:
        running_time = now
    elif running_time - now > time_per_request:
        # Convert diff back to a floating point number of seconds and sleep
        eventlet.sleep((running_time - now) / clock_accuracy)

    # Return the absolute time for the next interval in milliseconds; note
    # that time could have passed well beyond that point, but the next call
    # will catch that and skip the sleep.
    return running_time + time_per_request
github open-io / oio-sds / oio / common / client.py View on Github external
def _exp_sleep(attempts):
        """Sleep an exponential amount of time derived from `attempts`."""
        limit = pow(2, attempts)
        k = randrange(limit)
        sleep(k * ProxyClient._slot_time)
github openstack / cinder / cinder / volume / drivers / inspur / as13000 / as13000_driver.py View on Github external
def _check_volume(self, volume):
        """Check if the volume exists in the backend."""
        pool = volume_utils.extract_host(volume.host, 'pool')
        volume_name = self._trans_name_down(volume.name)
        attempts = 3
        while attempts > 0:
            volumes = self._get_volumes(pool)
            attempts -= 1
            for vol in volumes:
                if volume_name == vol.get('name'):
                    return True
            eventlet.sleep(1)
        return False
github noisyboiler / wampy / wampy / peers / bases.py View on Github external
def _wait_for_message(self):
        q = self._message_queue
        while q.qsize() == 0:
            # if the expected message is not there, switch context to
            # allow other threads to continue working to fetch it for us
            eventlet.sleep(0)

        message = q.get()
        return message
github tonybaloney / retox / retox / reporter.py View on Github external
def _loopreport(self):
        '''
        Loop over the report progress
        '''
        while 1:
            eventlet.sleep(0.2)
            ac2popenlist = {}
            for action in self.session._actions:
                for popen in action._popenlist:
                    if popen.poll() is None:
                        lst = ac2popenlist.setdefault(action.activity, [])
                        lst.append(popen)
                if not action._popenlist and action in self._actionmayfinish:
                    super(RetoxReporter, self).logaction_finish(action)
                    self._actionmayfinish.remove(action)

            self.screen.draw_next_frame(repeat=False)