Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This happens to a function in an imported module that is still executing after that module is garbage collected.</p> <p>Since your code isn't enough to reproduce the issue, here's a simplified example that shows the behaviour. Create a file containing the following and import it either from the Python command line or from another file. It doesn't work if you just run it at the top level.</p> <pre><code>import sys import threading x = "foo" def run(): while True: print "%s %s\n" % (sys, x) threading.Thread(target = run).start() sys.stdin.readline() </code></pre> <p>Running it:</p> <pre><code>$ python &gt;&gt;&gt; import evil_threading &lt;module 'sys' (built-in)&gt; foo &lt;module 'sys' (built-in)&gt; foo ... press Ctrl-C None None None None ... press Ctrl-\ to kill the Python interpreter </code></pre> <p>During Python shutdown, modules are set to <code>None</code>. <a href="https://stackoverflow.com/q/25649676/509706">This is an obscure Python behaviour that was removed in 3.4</a>. In this example, terminating the main thread results in shutdown, but the other thread is still running, so it sees the modules as <code>None</code>.</p> <p>There is a simpler example <a href="http://grokbase.com/t/python/python-list/035r7sjsnj/module-gets-garbage-collected-its-globals-become-none" rel="nofollow noreferrer">from here</a> which does the same thing by deleting the module reference directly from sys.modules.</p> <pre><code>import sys print sys del sys.modules['__main__'] print sys </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload