extending/embedding with triggers

Björn Fahller bjorn at algonet.se
Sun Apr 13 05:53:38 EDT 2003


Hello all,

Sorry for probably wanting to do something rather backwards...

I want to use Python as the scripting language in my program, but I'm facing 
two problems that I don't understand how I can solve with the public 
extention/embedding API. Perhaps it's doable inside Python itself.

I would like to express, in my python code, something like:

def func1():
  ...

def func2():
  ...

trig1 = mymodule.trigger(condition1)
trig2 = mymodule.trigger(condition2)
trigger.condition([(trig1,func1),(trig2,func2)])
... do something here, with many calls to mymodule

trigger.disarm([trig1,trig2])

The idea is that mymodule will some time call a function that will make the 
conditions held by the triggers become true. When they do, I want the 
functions to be executed. I cannot use a normal "if" statement, since I do 
not know when the trigger will become true, it can be anytime between 
"trigger.condition" and "trigger.disarm". Typically the functions are small 
and will, for example, acknowledge the condition to the module (but I want to 
control how it will be acknowledged in the script.)

The second problem is similar in that it too deals with triggers, but it also 
adds parallellism. In this case, most of the execution is driven by triggers.

def path1():
 trigger.awit_one_shot(mymodule.trigger(condition1))
 mymodule.somefunc()
 trigger.awit_one_shot(mymodule.trigger(condition2))
 mymodule.otherfunc()

def path2():
  trigger.await_one_shot(mymodule.trigger(condition3))
  mymodule.alternativefunc()


mymodule.do_something()
path.parallell([path1,path2])
mymodule.finish_something()

The thing here is that the my module will do all the work in both path1 and 
path2, between "do_something" and "finish_something", but the order between 
them is undefined and can be path1 before path2, the reversed, or 
interleaved. With a good generic problem to the first, this could be solved 
with threading, but I'd rather not need to make "mymodule" thread-aware.
   _
/Bjorn.






More information about the Python-list mailing list