Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Task:
- def __init__(task_defintion):
- pass
- def run()
- pass
- class A:
- def __init__():
- self.foo = "awesome variable"
- self.bar = "more awesome variable"
- # Initialize tasks based on some criterion
- self.tasks = [Task("A"), Task("B"), ....]
- def run_all():
- # These tasks can run in parallel
- for task in self.tasks:
- task.run() # Caveat is "task" would need to read member variables of
- # "A" like `foo`, `bar` etc ... Even task can write some
- # member variables to "A"
- # Is this a common design pattern ?
- # In simple terms, tasks created inside instance of "A" should
- # have some shared memory that they can read/write to.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement