2

So I'm running into an increasingly annoying problem while using Oct2Py in my python code to run a few Matlab codes. Every time I run Oct2py in my script it opens in my processes an octave-cli.exe *32 for each one but does not close it after the process is finished. Since I have multiple uses of it and now wish to have a loop of about a thousand this has become a problem.

Is there some command I can give to close the octave client after the run has been performed? I haven't found any references about this.

Something like:

ans = oc.read_file(filename)
close(octave)
Suever
  • 64,497
  • 14
  • 82
  • 101
Telesto
  • 67
  • 1
  • 3

1 Answers1

1

The exit method of the Oct2Py class will close the underlying Octave session.

ans = oc.read_file(filename)
oc.exit()

The constant spawning of Octave sessions in a loop may itself be a performance bottleneck. it may be worth writing your code such that you can reuse the Oct2Py instance each time through the loop.

octave = Oct2Py()

for filename in filenames:
    # Call Octave command
    output = octave.read_file(filename)

    # Perform any necessary cleanup
Suever
  • 64,497
  • 14
  • 82
  • 101
  • Thanks so much! Yeah I know I need to work on the efficiency of my code skills but if only there was enough time. But the exit command did work, thanks. – Telesto Nov 30 '16 at 02:21