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 details)

Uploaded Source

File details

Details for the file goal_oriented-0.1.tar.gz.

File metadata

  • Download URL: goal_oriented-0.1.tar.gz
  • Upload date:
  • Size: 2.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for goal_oriented-0.1.tar.gz
Algorithm Hash digest
SHA256 0dbf815cebc788c4bc2a100918a83b3157865323f6846e31252524ec5e7c3ad5
MD5 b3e3953e10c40e3427b3363128dac8c4
BLAKE2b-256 8dbf0afcc65d9b236588a629132acb8da0ec5c19a295e341ecab92eef3f1d0f6

See more details on using hashes here.

Supported by

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