def generator(): with atomic(*range(10)) << 'subgenerator': value = transport.value[0] yield value with atomic(value) << _: yield value + 10 subgenerator(value)
def test(): yield 0 with atomic() << _: yield 2 with atomic() << _: yield 3 with atomic() << _: yield 4 yield 1
def squares_of_range(x): for i in range(1, x): with atomic() << _: # this runs inside `multiprocesing.Pool` and transparently # takes `i` variable from outer world yield i*i #internally required modules are passed inside too time.sleep(round(random.random(), 3))
def status(*urls): with atomic(*urls) << _: yield (transport.status_code, transport.url, "set-cookie" in transport.headers.keys()) with Http.context("http://google.com.ua/"): yield (transport.status_code, transport.url, "set-cookie" in transport.headers.keys()) with Http.context("http://google.com.ua/"): yield (transport.status_code, transport.url, "set-cookie" in transport.headers.keys()) with Http.context("http://google.com.ua/"): yield (transport.status_code, transport.url, "set-cookie" in transport.headers.keys())
def test(): yield 0 with atomic() << _: yield 2 with atomic() << _: yield 5 with atomic() << _: yield 6 with atomic() << _: yield 3 with atomic() << _: yield 7 with atomic() << _: yield 8 with atomic() << _: yield 4 with atomic() << _: yield 9 with atomic() << _: yield 10 yield 1
def subgenerator(value): with atomic(value) << _: yield value + 100