VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Module caching (https://forums.vandyke.com/showthread.php?t=12852)

metallicat 10-05-2017 09:55 PM

Module caching
 
Hi,

I wrote my own module to use with my scripts in SecureCRT.
It's still in active development, I test the module by running scripts that use it.
However it looks like SecureCRT caches the module somewhere because the changes I make to the module are not reflected as fast as I'd expect.
I thought that restarting the session that has a script that uses the module attache would be enough to reinitialize it. That wasn't the case. Then I noticed that a <module>.pyc file is created, so I figured that's the file that is used when I reconnect. However erasing it didn't help. Even restarting SecureCRT and erasing the .pyc file doesn't help.

When I change the script that's attached to the session (or called by a mapped key) I notice the changes immediately after reconnecting the session. The issue is only with modules called inside the script.

Can you shed some light on the script initialization process in SecureCRT?

Cheers!
Alex.

bgagnon 10-06-2017 10:39 AM

Hi Alex,

Have you tried reload(module_name)?

metallicat 10-07-2017 12:17 AM

Hi Brenda,

Where should I try it exactly?

bgagnon 10-09-2017 07:34 AM

Hi Alex,

You might try searching Python documentation and other internet resources for answers to Python-specific questions.

The one statement I did find on Python's website:

Quote:

Note: For efficiency reasons, each module is only imported once per interpreter session. Therefore, if you change your modules, you must restart the interpreter or, if its just one module you want to test interactively, use reload(), e.g. reload(modulename).
Therefore, at any point in your script where you might be making changes you want to be reflected in the script, you would probably need to use reload().

metallicat 10-09-2017 06:55 PM

Hi Brenda,

The question is relevant here since SecureCRT controls the interpreter.
Reload command makes sense if I use a python console, which I don't (can't really with SecureCRT).
It doesn't make sense to add the reload(<module>) command to the script itself.
In my understanding the interpreter should stop once a script is finished.
The behavior I'm seeing is that SecureCRT doesn't restart the interpreter even when I close the application and open it again.
Is that correct?

bgagnon 10-10-2017 10:22 AM

Hi Alex,

SecureCRT does cache the module as long as it is running. If you are seeing behavior where the cache is not cleared after quitting/restarting SecureCRT then perhaps we need further details regarding your installation. (What version of SecureCRT? On what OS? etc.)

You should be adding reload() following import as shown in this post.

You may also need to make use of the variable PYTHONDONTWRITEBYTECODE as explained in these posts on Stack Overflow:
http://stackoverflow.com/questions/1...instead-of-pyc
http://stackoverflow.com/questions/3...er-changing-it

metallicat 10-11-2017 05:21 PM

I'm running version 8.3.0 (build 1474) on MacOS Sierra 10.12.5.
Python version 2.7.10.

bgagnon 10-12-2017 07:07 AM

Hi Alex,

My manager has posted some useful info here. Please review it.

metallicat 10-12-2017 09:10 PM

Thanks, Brenda.


All times are GMT -6. The time now is 02:14 PM.