<h3 dir="auto">Problem</h3>
<p dir="auto"><code class="notranslate">cli.py:shell_command</code> (flask shell) creates a context and passes it to <code class="notranslate">code.interact</code><br>
This leaves tab completion broken:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; stuff = 5
&gt;&gt;&gt; stuTABTABTABTAB &lt;- no match"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; stuff = 5
&gt;&gt;&gt; stuTABTABTABTAB &lt;- no match
</code></pre></div>
<h3 dir="auto">Suggestion</h3>
<p dir="auto">This can be remedied by supplying a completer to readline:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import readline
&gt;&gt;&gt; import rlcompleter
&gt;&gt;&gt; readline.set_completer(rlcompleter.Completer(globals()).complete)
&gt;&gt;&gt; stuTAB &lt;- stuff! yay!"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; import readline
&gt;&gt;&gt; import rlcompleter
&gt;&gt;&gt; readline.set_completer(rlcompleter.Completer(globals()).complete)
&gt;&gt;&gt; stuTAB &lt;- stuff! yay!
</code></pre></div>
<p dir="auto">Or perhaps <code class="notranslate">flask/__main__.py</code> could be used as the context:</p>
<p dir="auto"><em>file: flask/cli.py</em></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="...
def shell_command():
...
    import __main__
    ctx = __main__.__dict__
..."><pre class="notranslate"><code class="notranslate">...
def shell_command():
...
    import __main__
    ctx = __main__.__dict__
...
</code></pre></div>
<p dir="auto">When I running a flask app with debug=True in virtualenv, the cpu usage increase to 20%. But if I set debug=False, the cpu usage is only 1%.<br>
If I running without virtualenv, all is ok.</p>