importing new jython tools when running in a jython shell

Post any questions, ideas, or topics related to Jython and Python scripting.
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

A new problem: when using listADDEImages, the jython shell opens, executes the command and exit() as expected. However, when running loadADDEImages, the jython shell opens, executes the command and never honors the exit(). Do you know how to clean up at the end of the script so that the script exits properly?

Thanks,
Joleen
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: importing new jython tools when running in a jython shell

Post by Jon »

You shouldn't need to do anything differently--but I'll dig into it.

One thing to try is simply putting a "print" statement immediately after the loadADDEImage call. Presumably you'd see the output after loadADDEImage finishes.
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

I did add a print statement and I do see the print. Everything seems to run fine, the shell never exits. I dug around and thought it might be a open file handle or something like that, but I removed all the code except the listADDEImages/loadADDEImages. You should be able to test with attached code. Set processThisTime=True to use loadADDEImages, processThisTime=False to use listADDEImages.

Thanks,
Joleen

example.py
(2.02 KiB) Downloaded 316 times
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

Right now, I have my statistics code running in .local/lib/jython2.7/site-packages.

I am now creating code which I will need to access from both the statistics code and through the jython library (~McIDAS-V/python). What is the best way to approach linking these pieces. I was thinking that the code should go into the normal location of ~McIDAS-V/python but I am not exactly sure I would know how to import those code pieces for the statistics code which does not start the whole McV package, but uses the mcvinit script and usercustomize in .local/lib/jython2.7/site-packages.

Thanks,
Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

I have moved to a new machine. The code I had been running to initiate a session of McV without the display (just use McV libs including the McIDAS-V scripting API) was located in .local/lib/jython2.7/site-packages. When I installed McIDAS-V on the new machine, this directory was not created. Is there a new directory tree or is this just a directory tree I should create to continue running this work as I had on the old machine?

Thanks,
Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: importing new jython tools when running in a jython shell

Post by joleenf »

Hi Jon,

I fixed this problem for myself. I forgot that we created the directory tree .local/lib/jython2.7/site-packages when we added usercustomize.py. I created the directory tree on my new computer, and the old code is running.

Joleen
User avatar
Jon
Posts: 192
Joined: Fri Jan 09, 2009 8:44 pm
Location: Madison, WI

Re: importing new jython tools when running in a jython shell

Post by Jon »

Hi Joleen,

Sorry for the silence on my end. Every time I sit down to type up a reply, I wind up trying to fix the problem instead of just replying. :oops:

(on the plus side, I have a batch of commits coming up that you'll probably like)

As for the actual problem, I get bitten by the same thing from time to time--and it doesn't help that "~/.local" doesn't leap out as something that contains Python modules. I can think of two ways to mitigate this problem, but they're not great because they still require you to remember to run some shell command when setting up a new computer:

  • Do all of your "dotfile" stuff in a Git repository, and probably host the repo on SSEC's Gitlab instance, or possibly https://gitlab.com or Bitbucket (they all offer free private repository hosting).
    When setting up a new computer, you'd have to remember to clone the repo and then (probably) run some sort of bootstrapping script to set up symlinks (e.g. ~/.bashrc -> /some/repo/path/.bashrc).
    GNU Stow is basically a tool for doing what I've outlined. It's also worth noting that dotfile management seems to be one of those things that you can spend forever trying to make perfect!
  • Keep your dotfiles in Dropbox. The difference is that Dropbox would automatically keep your dotfiles in sync across all of your machines; no "git commit; git push" and "git pull" steps! The symlinking step would probably still be required.

All that stuff said, I'd really like to trim down the McV background startup process to the point where it performs similarly to running Jython and importing the relevant code as needed.
Post Reply