26 lines
604 B
Python
26 lines
604 B
Python
# -*- mode: python -*-
|
|
|
|
from datetime import timedelta
|
|
from time import sleep
|
|
from flowmetal import workflow, timeout, CancelledError, TimeoutError, Task
|
|
|
|
|
|
def cancellable_activity():
|
|
try:
|
|
while True:
|
|
print("Still alive")
|
|
sleep(0.5)
|
|
except CancelledError:
|
|
print("Task killed")
|
|
|
|
|
|
@workflow
|
|
def main():
|
|
# Somewhat like a thread
|
|
t = Task(target=cancellable_activity, args=(), timeout=timedelta(minutes=5))
|
|
t.start()
|
|
try:
|
|
result = t.result(timeout=timedelta(seconds=3))
|
|
print(result)
|
|
except TimeoutError:
|
|
t.cancel()
|