title: Simpy - when to use yield and when to call the function
body: <p>I am trying to use Simpy to model some behavior of moving cars around a city grid.  However, I am having some trouble wrapping my head conceptually around when to use something like </p>
  
  <p><code>yield self.env.timeout(delay)</code>  or <code>yield env.process(self.someMethod())</code> 
  versus just calling the method <code>self.someMethod()</code>.</p>
  
  <p>On a very theoretical level, I understand <code>yield</code> statements and generators as to how they apply to iterables but not quite sure how it relates to <code>Simpy</code>.  </p>
  
  <p>The <code>Simpy</code> tutorials are still quite dense.  </p>
  
  <p>For example: </p>
  
  <pre><code>class Car(object):
      def __init__(self, env, somestuff):
          self.env = env
          self.somestuff = somestuff
  
          self.action = env.process(self.startEngine())  # why is this needed?  why not just call startEngine()?
  
      def startEngine(self):
          #start engine here
          yield self.env.timeout(5) # wait 5 seconds before starting engine
          # why is this needed?  Why not just use sleep? 
  
  
  
  env = simpy.Environment()
  somestuff = "blah"
  car = Car(env, somestuff)
  env.run()
  </code></pre>