Re: How to unload a module after I've imported it.



En Sat, 29 Sep 2007 17:32:15 -0300, marvinla <marvinware2005@xxxxxxxxx> escribi�:

Have you tried a del?

import socket
dir()
['__builtins__', '__doc__', '__name__', 'socket']
del socket
dir()
['__builtins__', '__doc__', '__name__']

py> import socket
py> del socket
py> import sys
py> sys.modules['socket']
<module 'socket' from 'c:\apps\Python25\lib\socket.pyc'>

del only removes the reference from the current namespace, but the module is still loaded and available.
del sys.modules['socket'] would remove the module so the next import statement will have to reload it.

Back to the original question, timeoutsocket replaces some objects in the socket module with its own versions, just "unloading" timeoutsocket would not be enough, the changes had to be reverted.

timeoutsocket is an old hack for Python 2.2 and earlier. Since 2.3 you can achieve the same thing using socket.setdefaulttimeout() so unless you are forced to use such ancient versions, it can be dropped.

--
Gabriel Genellina

.



Relevant Pages

  • Re: urllib hangs
    ... The author of timeoutsocket was in fact not clear about the location ... On it's face it doesn't make sense that importing ... > timeoutsocket would magically override the behaviour of socket without ... > timeoutsocket.py into the base python distro because, again, it seems ...
    (comp.lang.python)
  • Re: urllib hangs
    ... On it's face it doesn't make sense that importing ... > timeoutsocket would magically override the behaviour of socket without ... It may seem odd, but it does in fact say something ...
    (comp.lang.python)