<div  id="add-an-event">
<span id="add-event"></span><span id="index-0"></span>
<div >
<div >Sometimes waiting for the completion of a task is not good enough.</div>
<div >If a task is producing several results, another task may start as</div>
<div >soon as the first results are ready.</div>
<div >For that, ecFlow introduces the concept of <a  href="/wiki/display/ECFLOW/Glossary#term-event"><em >event</em></a>&#8216;s.</div>
</div>
<div >
<div >An <a  href="/wiki/display/ECFLOW/Glossary#term-event"><em >event</em></a> is a message that a task will report to ECF while</div>
<div >it is running.</div>
</div>
<p>Events have names and a <a  href="/wiki/display/ECFLOW/Glossary#term-task"><em >task</em></a> can set several of them:</p>
<div ><pre># Definition of the suite test.
suite test
   edit ECF_INCLUDE "$HOME/course"
   edit ECF_HOME    "$HOME/course"
   family f1
     edit SLEEP 20
     task t1
     task t2
         trigger t1 eq complete
         event a
         event b
     task t3
         trigger t2:a
     task t4
         trigger t2:b
   endfamily
endsuite</pre>
</div>
<p>In python this would be like:</p>
<div ><div ><pre><span >#!/usr/bin/env python2.5</span>
<span >import</span> <span >os</span>
<span >import</span> <span >ecflow</span> 

<span >def</span> <span >create_family_f1</span><span >():</span>
    <span >f1</span> <span >=</span> <span >ecflow</span><span >.</span><span >Family</span><span >(</span><span >&quot;f1&quot;</span><span >)</span>
    <span >f1</span><span >.</span><span >add_variable</span><span >(</span><span >&quot;SLEEP&quot;</span><span >,</span><span >20</span><span >)</span>
    <span >f1</span><span >.</span><span >add_task</span><span >(</span><span >&quot;t1&quot;</span><span >)</span>
    <span >t2</span> <span >=</span> <span >f1</span><span >.</span><span >add_task</span><span >(</span><span >&quot;t2&quot;</span><span >)</span>  
    <span >t2</span><span >.</span><span >add_trigger</span><span >(</span><span >&quot;t1 eq complete&quot;</span><span >)</span> 
    <span >t2</span><span >.</span><span >add_event</span><span >(</span><span >&quot;a&quot;</span><span >)</span>
    <span >t2</span><span >.</span><span >add_event</span><span >(</span><span >&quot;b&quot;</span><span >)</span>
    <span >t3</span> <span >=</span> <span >f1</span><span >.</span><span >add_task</span><span >(</span><span >&quot;t3&quot;</span><span >)</span>
    <span >t3</span><span >.</span><span >add_trigger</span><span >(</span><span >&quot;t2:a&quot;</span><span >)</span>  
    <span >t4</span> <span >=</span> <span >f1</span><span >.</span><span >add_task</span><span >(</span><span >&quot;t4&quot;</span><span >)</span>
    <span >t4</span><span >.</span><span >add_trigger</span><span >(</span><span >&quot;t2:b&quot;</span><span >)</span>  
    <span >return</span> <span >f1</span>

<span >defs</span> <span >=</span> <span >ecflow</span><span >.</span><span >Defs</span><span >()</span>
<span >suite</span> <span >=</span> <span >defs</span><span >.</span><span >add_suite</span><span >(</span><span >&quot;test&quot;</span><span >)</span>
<span >suite</span><span >.</span><span >add_variable</span><span >(</span><span >&quot;ECF_INCLUDE&quot;</span><span >,</span><span >os</span><span >.</span><span >getenv</span><span >(</span><span >&quot;HOME&quot;</span><span >)</span> <span >+</span> <span >&quot;/course&quot;</span><span >)</span>
<span >suite</span><span >.</span><span >add_variable</span><span >(</span><span >&quot;ECF_HOME   &quot;</span><span >,</span><span >os</span><span >.</span><span >getenv</span><span >(</span><span >&quot;HOME&quot;</span><span >)</span> <span >+</span> <span >&quot;/course&quot;</span><span >)</span>

<span >suite</span><span >.</span><span >add_family</span><span >(</span> <span >create_family_f1</span><span >()</span> <span >)</span>
</pre></div>
</div>
<div >
<div >To notify <a  href="/wiki/display/ECFLOW/Glossary#term-ecflow-server"><em >ecflow_server</em></a>, the task <strong>t2</strong> must call</div>
<div ><a  href="/wiki/display/ECFLOW/Glossary#term-ecflow-client"><em >ecflow_client</em></a> &#8211;event which is one of the <a  href="/wiki/display/ECFLOW/Glossary#term-child-command"><em >child command</em></a>&#8216;s</div>
</div>
<div ><pre>%include &lt;head.h&gt;
echo "I will now sleep for %SLEEP% seconds"
sleep %SLEEP%
ecflow_client --event a       # Set the first event
sleep %SLEEP%                 # Sleep a bit more
ecflow_client --event b       # Set the second event
sleep %SLEEP%                 # A last nap...
%include &lt;tail.h&gt;</pre>
</div>
<p>What to do:</p>
<ol >
<li>Edit the definition or python file to add the modifications.</li>
<li>Edit <tt ><span >t2.ecf</span></tt> to call <a  href="/wiki/display/ECFLOW/Glossary#term-ecflow-client"><em >ecflow_client</em></a> &#8211;event.</li>
<li>Copy <tt ><span >t1.ecf</span></tt> to <tt ><span >t3.ecf</span></tt> and <tt ><span >t4.ecf</span></tt></li>
<li>Load the definition again.</li>
<li>Observe the tasks in <a  href="/wiki/display/ECFLOW/Glossary#term-ecflowview"><em >ecflowview</em></a>.</li>
<li>See the triggers by selecting <strong>t3</strong> and clicking on the icon <img alt="triggers" src="/wiki/download/attachments/7373012/triggers.jpg" /></li>
<li>See the triggers by selecting <strong>t2</strong> and click on <strong>Dependencies</strong></li>
</ol>
</div>