title: Heroku: how to programatically restart or shut down a dyno from an application running on that dyno
body: <p>I have a scrapy scraper running on Heroku. I want to restart the scraper as soon as it finishes. What is the best way to achieve this? </p>
  
  <ul>
  <li>The obvious solution would be to kill or restart that dyno, then Heroku will rerun the scraper via the procfile. However, it's not clear what the best way to do this is. </li>
  </ul>
  
  <p>Related: does Heroku automatically detect that your process has stopped running and automatically shut down the dyno for you? Or does the dyno just sit there doing nothing?</p>
  
  <p>Related #2: could you call a python script/program from within your scraper just before it exits, then that script could wait 5 seconds and then execute</p>
  
  <pre><code>scrapy runspider myspider
  </code></pre>
  
  <p>Would that work? Presumably trying to execute </p>
  
  <pre><code>scrapy runspider myspider
  </code></pre>
  
  <p>from <em>within</em> the spider itself will cause the universe to implode or something (twisted error probably)? </p>