Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-05-2017, 10:55 PM
metallicat metallicat is offline
Registered User
 
Join Date: Sep 2017
Posts: 21
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.
Reply With Quote
  #2  
Old 10-06-2017, 11:39 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,179
Hi Alex,

Have you tried reload(module_name)?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 10-07-2017, 01:17 AM
metallicat metallicat is offline
Registered User
 
Join Date: Sep 2017
Posts: 21
Hi Brenda,

Where should I try it exactly?
Reply With Quote
  #4  
Old 10-09-2017, 08:34 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,179
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().
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 10-09-2017, 07:55 PM
metallicat metallicat is offline
Registered User
 
Join Date: Sep 2017
Posts: 21
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?

Last edited by metallicat; 10-09-2017 at 09:03 PM.
Reply With Quote
  #6  
Old 10-10-2017, 11:22 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,179
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
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #7  
Old 10-11-2017, 06:21 PM
metallicat metallicat is offline
Registered User
 
Join Date: Sep 2017
Posts: 21
I'm running version 8.3.0 (build 1474) on MacOS Sierra 10.12.5.
Python version 2.7.10.
Reply With Quote
  #8  
Old 10-12-2017, 08:07 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 3,179
Hi Alex,

My manager has posted some useful info here. Please review it.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #9  
Old 10-12-2017, 10:10 PM
metallicat metallicat is offline
Registered User
 
Join Date: Sep 2017
Posts: 21
Thanks, Brenda.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 08:37 AM.