Signal problem

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Mar 27 16:07:24 EDT 2008


En Thu, 27 Mar 2008 16:27:16 -0300, Fabio Durieux Lopes  
<durieux_br at yahoo.com.br> escribió:

>    On daemon.py I have:
>
> terminate = False
>
> def signalHandler(signum, frame):
>    terminate = True
>
>    And my main loop goes like this:
>
>    'while(not daemon.terminate):'
>
>    When the signal treatment was in the same file as my loop it
> worked just fine, and since I've separated it in another file it
> stopped working. The SIGALRM treatment, which remains in the same
> file, is still working. Any reason why it doesn't treat SIGTERM
> anymore? Does it have anything to do with the fact that 'terminate'
> is not a class variable? Any ideas?

Is "daemon.py" your main entry point? That is, is it the one you execute?
In that case, the module is initially imported as "__main__", not as  
"daemon"; if you "import daemon" from another file, you'll end with TWO  
different loaded modules for the SAME file (because "daemon" was not in  
sys.modules, so Python thinks it was not imported yet, and loads it again).
A rule might say: Your main script may import anything, but no one may  
import the main script.

-- 
Gabriel Genellina




More information about the Python-list mailing list