Skip to main content

This module provides a simple facility to the goal-oriented programming paradigm.

Project description

This module provides a simple facility to the goal-oriented programming paradigm.

In goal-oriented programming, the programmer subdivides the problem in minor goals,
with dependencies between them, and just pass them to a scheduler that will
execute them asyncronously and in the correct order.

===

In this implementation every goal function receives three arguments:
name -- the unique name of the goal
args -- the results from its dependencies
results -- a dictionary where it can write a return value
(readable by subcessive goals)

The test cointained in the module file illustrates how the module must be used.

===

An example of usage:

"""Usage example"""

def goal1(name, args, results):
print name, args
sleep(1)
results[name] = name + " completed!"

def goal2(name, args, results):
print name, args
sleep(2)
results[name] = name + " completed!"

def goal3(name, args, results):
print name, args
sleep(2)
results[name] = name + " completed!"

def goal4(name, args, results):
print name, args
sleep(1)
results[name] = name + " completed!"

def goal5(name, args, results):
print name, args
sleep(3)
results[name] = name + " completed!"

def goal6(name, args, results):
print name, args
sleep(1)
results[name] = name + " completed!"

# goals to run and their dependencies
schedule_goals( goal1 = { 'target': goal1 },
goal2 = { 'target': goal2 },
goal3 = { 'target': goal3, 'deps': ['goal1', 'goal2'] },
goal4 = { 'target': goal4, 'deps': ['goal3'] },
goal5 = { 'target': goal5, 'deps': ['goal2'] },
goal6 = { 'target': goal6 } )

===

Output of the example:

$ python goal_oriented.py

goal6 {}
goal2 {}
goal1 {}
goal5 {'goal2': 'goal2 completed!'}
goal3 {'goal2': 'goal2 completed!', 'goal1': 'goal1 completed!'}
goal4 {'goal3': 'goal3 completed!'}

real 0m5.018s
user 0m0.104s
sys 0m0.052s

===

Have fun... :)

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

goal_oriented-0.1.tar.gz (2.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page