Hello, I don't know if my question is more zopish or pythonish. I have a Zope product. I had to add the specific functionality which is needed very rarely. I would be glad to import external module only when it is needed, do the job and free my mind and extra memory it consumed. How should I do that? I have to admit that I don't find myself as an experienced Python programmer. I just discover depths of this incredible language while extending my Zope product. Maybe anyone would help me with some relevant links. Thanx in advance, Pawel Lewicki
Hello Pawel, This is quite a gotcha! :-) Try: import mymodule #NOW IT'S LOADED del ( mymodule ) #HERE IT SHOULD UNLOAD Well, since loaded modules are nothing but objects, you can use the same functions and calls as you use on standard objects in Python. What the modules would return to standard operations, that's another story - but the 'del' should definitely work. -Mac -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Pawel Lewicki Sent: Tuesday, April 08, 2003 6:56 PM To: zope@zope.org Subject: [Zope] Dynamic script loading Hello, I don't know if my question is more zopish or pythonish. I have a Zope product. I had to add the specific functionality which is needed very rarely. I would be glad to import external module only when it is needed, do the job and free my mind and extra memory it consumed. How should I do that? I have to admit that I don't find myself as an experienced Python programmer. I just discover depths of this incredible language while extending my Zope product. Maybe anyone would help me with some relevant links. Thanx in advance, Pawel Lewicki _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Jan Ma-Bška wrote at 2003-4-9 10:40 +0200:-A
This is quite a gotcha! :-) Try:
import mymodule #NOW IT'S LOADED del ( mymodule ) #HERE IT SHOULD UNLOAD
This is *very* unlikely. First of all, there is a reference in "sys.modules". Then, when "mymodules" defines functions or methods, they reference "mymodule" and prevent unloading. You can try: mymodule.__dict__.clear() # this clears the module import sys; del sys.modules['mymodule'] del mymodule When there are no longer any instances of classes defined in "mymodule", it may unload... Dieter
Pawel Lewicki wrote at 2003-4-8 18:56 +0200:
I don't know if my question is more zopish or pythonish. I have a Zope product. I had to add the specific functionality which is needed very rarely. I would be glad to import external module only when it is needed, do the job and free my mind and extra memory it consumed. How should I do that? I have to admit that I don't find myself as an experienced Python programmer. I just discover depths of this incredible language while extending my Zope product. Maybe anyone would help me with some relevant links.
Unless, your code is huge and your resources very limited, I would not worry at all. When you really want to get rid of the code, then you must delete *all* references (which may not be easy). There are hidden module references, e.g. "func_globals" in functions and in "sys.modules". Come back, when you really need it... Dieter
Pawel Lewicki wrote at 2003-4-9 22:59 +0200:
Unless, your code is huge and your resources very limited, I would not worry at all.
So I'll give it up. :) Is there any difference between loading module at the beginning of the code or inside the function?
Only a small one: Imported modules are cached (in "sys.modules"). Subsequent imports of the same module are therefore quite fast. When you put the import at module level, you import only once. Dieter
I've a big problem with smtphost and dtml-sendmail I encountered this problem when i ran this dtml codes: <dtml-sendmail smtphost="mail.mysmtphost.net"> To: <myaddress@mysmtphost.net> Message: I wish to see U later </dtml-sendmail> Error Type: SMTPSenderRefused Error Value: (505, 'Authentication required', 'myaddress@mysmtphost.net') I've the problem: the smtphost needed id and pwd but i don't know how send it! Can you say me a solutions please? Massimiliano
I encountered this problem when i ran this dtml codes:
<dtml-sendmail smtphost="mail.mysmtphost.net"> To: <myaddress@mysmtphost.net> Message: I wish to see U later </dtml-sendmail>
Error Type: SMTPSenderRefused Error Value: (505, 'Authentication required', 'myaddress@mysmtphost.net')
I've the problem: the smtphost needed id and pwd but i don't know how send it! Can you say me a solutions please?
The sendmail tag/MailHost combination does not support authenticated SMTP. You will need to roll your own solution or switch to a SMTP server that does not require authentication. jens
participants (5)
-
Dieter Maurer -
Jan Maška -
Jens Vagelpohl -
Pawel Lewicki -
trashMan