Most viewed recipes tagged "stack"http://code.activestate.com/recipes/tags/stack/views/2017-06-22T10:24:05-07:00ActiveState Code RecipesHow to debug (deadlocked) multi threaded programs (Python)
2010-07-26T15:39:15-07:00Laszlo Nagyhttp://code.activestate.com/recipes/users/4150221/http://code.activestate.com/recipes/577334-how-to-debug-deadlocked-multi-threaded-programs/
<p style="color: grey">
Python
recipe 577334
by <a href="/recipes/users/4150221/">Laszlo Nagy</a>
(<a href="/recipes/tags/dead/">dead</a>, <a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/lock/">lock</a>, <a href="/recipes/tags/stack/">stack</a>, <a href="/recipes/tags/thread/">thread</a>, <a href="/recipes/tags/trace/">trace</a>).
</p>
<p>Simple module that allows you to explore deadlocks in multi threaded programs.</p>
Simple Infix Expression Evaluation (Python)
2015-11-07T18:44:05-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/579122-simple-infix-expression-evaluation/
<p style="color: grey">
Python
recipe 579122
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/stack/">stack</a>).
</p>
<p>Simple infix expression evaluation using a stack.</p>
Infix Expression Evaluation (Python)
2015-11-08T05:08:26-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/579123-infix-expression-evaluation/
<p style="color: grey">
Python
recipe 579123
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/stack/">stack</a>).
</p>
<p>Infix expression evaluation using two stacks.</p>
backtrace2line - stack traces with source file name and line numbers (Python)
2010-12-20T06:57:29-08:00Jean Brouwershttp://code.activestate.com/recipes/users/2984142/http://code.activestate.com/recipes/534147-backtrace2line-stack-traces-with-source-file-name-/
<p style="color: grey">
Python
recipe 534147
by <a href="/recipes/users/2984142/">Jean Brouwers</a>
(<a href="/recipes/tags/backtrace/">backtrace</a>, <a href="/recipes/tags/backtrace_symbols_fd/">backtrace_symbols_fd</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/stack/">stack</a>, <a href="/recipes/tags/stacktrace/">stacktrace</a>).
Revision 3.
</p>
<p>This recipe reads a file containing stack traces from Linux' backtrace functions and extends each stack frame line with the source file name and line number. Usage and an example are included.</p>
Peek at Python value stack (Python)
2013-01-08T22:15:21-08:00Dima Tisnekhttp://code.activestate.com/recipes/users/4068698/http://code.activestate.com/recipes/578412-peek-at-python-value-stack/
<p style="color: grey">
Python
recipe 578412
by <a href="/recipes/users/4068698/">Dima Tisnek</a>
(<a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/stack/">stack</a>).
</p>
<p>Poking at value stack, a.k.a. evaluation stack is not allowed in Python, however everything is doable with ctypes.</p>
<p>I think this could be useful in debugging complex statements.</p>
Stack Environment (Python)
2017-06-22T10:24:05-07:00Alfehttp://code.activestate.com/recipes/users/4182236/http://code.activestate.com/recipes/578147-stack-environment/
<p style="color: grey">
Python
recipe 578147
by <a href="/recipes/users/4182236/">Alfe</a>
(<a href="/recipes/tags/environment/">environment</a>, <a href="/recipes/tags/global/">global</a>, <a href="/recipes/tags/stack/">stack</a>, <a href="/recipes/tags/stackenv/">stackenv</a>, <a href="/recipes/tags/variable/">variable</a>).
Revision 3.
</p>
<p>The environment variables of processes get inherited by their children who can modify them and pass them on to their children. The tree of processes is similar to the call tree of a running Python process, but a similar mechanism like the environment variables is missing. I'm offering a solution for this; each stack frame takes the place of a process, hence I call it StackEnv. It comes in handy if you want to pass information from one frame to a frame far below without patching all the calls in between to pass the data (which might belong to a framework you don't want to change).</p>
<p>Usecases:</p>
<ol>
<li><p>You call a framework which calls back your code before returning (e. g. in passed objects you provide). You want to pass some information to your code without relying on global variables or similar constructs which weren't thread-safe nor re-entrant.</p></li>
<li><p>You want to pass pseudo-global but in fact situation-related information (e. g. the verbosity based on the situation the call comes from) without handing the information down in each and every call which can happen below yours.</p></li>
<li><p>You want to give called methods the option to override the decision of the caller method regarding this information. (E. g. the caller decides that verbosity should be True, but the called method then calls another method and decides that the verbosity in this case should be False.)</p></li>
</ol>
<p>Alike processes, called frames cannot influence the values for calling frames (but of course mutable values <em>can</em> be used to pass information upwards; this normal kind of "abuse" isn't prevented).</p>
<p>Importing:</p>
<pre class="prettyprint"><code>from stackEnv import stackEnv
</code></pre>
<p>Setting a stackEnv variable:</p>
<pre class="prettyprint"><code>stackEnv.verbose = True
</code></pre>
<p>Using the value of a stackEnv variable:</p>
<pre class="prettyprint"><code>if stackEnv.verbose: print "being verbose now"
</code></pre>
<p>Testing a stackEnv variable:</p>
<pre class="prettyprint"><code>if 'verbose' in stackEnv: print "having information on verbosity"
</code></pre>
<p>Overriding a stackEnv variable's value for the rest of this frame and its calls:</p>
<pre class="prettyprint"><code>stackEnv.verbose = False
</code></pre>
<p>Removing a stackEnv variable for the rest of this frame and its calls:</p>
<pre class="prettyprint"><code>del stackEnv.verbose
</code></pre>
<p>Some more useful API of this class can be found in the unit test included.</p>
small stack language (Python)
2013-07-22T23:53:44-07:00Andrew Wayne Teesdale Jr.http://code.activestate.com/recipes/users/4187305/http://code.activestate.com/recipes/578617-small-stack-language/
<p style="color: grey">
Python
recipe 578617
by <a href="/recipes/users/4187305/">Andrew Wayne Teesdale Jr.</a>
(<a href="/recipes/tags/language/">language</a>, <a href="/recipes/tags/stack/">stack</a>).
</p>
<p>a small language in python</p>