Popular recipes tagged "lookahead"http://code.activestate.com/recipes/tags/lookahead/2013-09-24T10:44:56-07:00ActiveState Code RecipesGenerator with lookahead (Python)
2013-09-24T10:44:56-07:00Rutger Saalminkhttp://code.activestate.com/recipes/users/4187940/http://code.activestate.com/recipes/578671-generator-with-lookahead/
<p style="color: grey">
Python
recipe 578671
by <a href="/recipes/users/4187940/">Rutger Saalmink</a>
(<a href="/recipes/tags/background/">background</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/generators/">generators</a>, <a href="/recipes/tags/lookahead/">lookahead</a>, <a href="/recipes/tags/performance/">performance</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>Python generators are a great way of reducing memory usage due to the lazy (on demand) generation of values. However, when the process-time of generating such a value is relatively high, we can improve performance even more by obtaining the next n values of the generator in a separate thread in the background. Hence, the BackgroundGenerator.</p>