Skip to content

Commit d723c1a

Browse files
Brandon Davisnetromdk
Brandon Davis
authored andcommitted
Add task.py for mapping tasks to ProcessPoolExecutor
Task is an abstract base class that implements a method for executing sub tasks by the process pool.
1 parent b0a6ca8 commit d723c1a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

slacker/task.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from abc import ABC, abstractmethod
2+
3+
from concurrent.futures import ProcessPoolExecutor
4+
5+
class Task(ABC):
6+
@abstractmethod
7+
def run():
8+
pass
9+
10+
def start_task(task):
11+
return task.run()
12+
13+
def execute_tasks(tasks):
14+
pool = ProcessPoolExecutor()
15+
return pool.map(start_task, tasks)

0 commit comments

Comments
 (0)