Did I find the right examples for you? yes no      Crawl my project      Python Jobs

# gruvi.util.sleep

All Samples(26)  |  Call(26)  |  Derive(0)  |  Import(0)

```        # the granularity of libuv's timers is 1ms. the statement below
# therefore sleeps 0ms 75% of the time, and 1ms 25% of the time.
util.sleep(random.randint(0, 12)/10000)
lock.acquire()
util.sleep(random.randint(0, 12)/10000)
```
```def lock_unlock_recursive(lock, count=10):
failed = 0
for i in range(count):
util.sleep(random.randint(0, 12)/10000)
lock.acquire()
util.sleep(random.randint(0, 12)/10000)
failed += (1 if lock.locked != 1 else 0)
lock.acquire()
util.sleep(random.randint(0, 12)/10000)
```

```        # the granularity of libuv's timers is 1ms. the statement below
# therefore sleeps 0ms 75% of the time, and 1ms 25% of the time.
util.sleep(random.randint(0, 12)/10000)
lock.acquire()
util.sleep(random.randint(0, 12)/10000)
```
```def lock_unlock_recursive(lock, count=10):
failed = 0
for i in range(count):
util.sleep(random.randint(0, 12)/10000)
lock.acquire()
util.sleep(random.randint(0, 12)/10000)
failed += (1 if lock.locked != 1 else 0)
lock.acquire()
util.sleep(random.randint(0, 12)/10000)
```

```        def fiber1():
local.foo = 10
interleaved.append(1)
util.sleep(0)
self.assertEqual(local.foo, 10)
local.foo = 30
interleaved.append(1)
util.sleep(0)
```
```        def fiber2():
self.assertFalse(hasattr(local, 'foo'))
local.foo = 20
interleaved.append(2)
util.sleep(0)
self.assertEqual(local.foo, 20)
local.foo = 40
interleaved.append(2)
util.sleep(0)
```

```        def fiber1():
local.foo = 10
interleaved.append(1)
util.sleep(0)
self.assertEqual(local.foo, 10)
local.foo = 30
interleaved.append(1)
util.sleep(0)
```
```        def fiber2():
self.assertFalse(hasattr(local, 'foo'))
local.foo = 20
interleaved.append(2)
util.sleep(0)
self.assertEqual(local.foo, 20)
local.foo = 40
interleaved.append(2)
util.sleep(0)
```