Пример #1
0
# Shows how the TasksGroup is used with functions with arguments.
# (see tgroups1.py)

from concurrent.futures import ThreadPoolExecutor
from futuro import TasksGroup

import time
tasks = TasksGroup()


def f(number, sleep_time):
    time.sleep(sleep_time)
    print(time.time(), number)

f1 = tasks.add()(lambda: f(1, .4))
f2 = tasks.add(f1)(lambda: f(2, 4))
f3 = tasks.add(f1)(lambda: f(3, .4))
f4 = tasks.add(f2, f3)(lambda: f(4, .4))

with ThreadPoolExecutor(max_workers=2) as executor:
    tasks.run(executor)
Пример #2
0
#!/usr/bin/env python

# Shows how the TasksGroup is used.

import time

# Import TasksGroup and create an instance
from futuro import TasksGroup
tasks = TasksGroup()

# Functions are added to the group using the `add` decorator.
@tasks.add()
def f1():
    time.sleep(.4)
    print(time.time(), 1)


# Dependencies are indicated in the arguments
@tasks.add(f1)
def f2():
    time.sleep(4)
    print(time.time(), 2)


@tasks.add(f1)
def f3():
    time.sleep(.4)
    print(time.time(), 3)


# Multiple dependencies can be specified