Quesion about running a exe file in Python(Not enough memory)

Y

yuyaxuan0

Hey guys,

I have a python script that will call an external exe file. Code is kind of like this:

import sys
import os
from helper_functions import strContains

if (len(sys.argv) != 4):
print('Usage of script: export_mirax_data <pathToSourceMiraxData> <pathToResultData> <tileSize>')
else:
print('Script to export mirax data')
print('---------------------------')

# default parameters for exporting
zoomLevel = 0 # 0 (original) - 9 (whole slide on one image)
tileHeight = 2048 # has to be a multiple of 256
tileWidth = 2048 # has to be a multiple of 256
fileFormat = "png" # jpg, png and bmp are allowed
mapFileFormat = "png" # xml, png and bmp are allowed

# implicitly needed parameters
MiraxSlideExporter = "MrxSlideExport.exe"

slicePath = sys.argv[1]
pathToResultData = sys.argv[2]
tileHeight = sys.argv[3]
tileWidth = sys.argv[3]

# slices = os.listdir(pathToSourceMiraxData)

# sys.argv[1]
# sys.argv[2]

# create command-line for system-call of mirax-slide-exporter
# -e exports the slide
# -i saves slide information in outputfolder
# -a optional
# -n only tiles which contain information are exported
# -s + pathToSourceMiraxData + \
cmdForExportingSlicesToTiles = \
MiraxSlideExporter + \
" -i " + \
" -e " + \
" -z " + str(zoomLevel) + \
" -t " + str(tileHeight) + " " + str(tileWidth) + \
" -f " + str(fileFormat) + \
" -m " + str(mapFileFormat) + \
" "

#cmd = "D:\\programs\\MIRAX_SlideAC_SDK\\Bin\\MrxSlideExport.exe -s D:\\fit\\projects\\bayer\\KidneyLiver\\MiraxScanner\\Slides\\L10 -e -o D:\\fit\\projects\\bayer\\KidneyLiver\\MiraxScanner\\Output\\L10 -z 5 -f png"
#os.system(cmd)
#msg = os.popen(cmd, mode='r', buffering=-1) # does not work
#print(msg)

# run through slices in given source-path


cmd = cmdForExportingSlicesToTiles + " -s " + slicePath + " -o " + pathToResultData
print(cmd)
os.system(cmd)



So the problem is that is says it doesn't have sufficient memory.

The weired thing is that if I just ran the exe file directly in cmd console, it's working without any memory problem. I am wondering whether if it's some kind of python issue limits the memory that we can use??
 
D

Dave Angel

Hey guys,

I have a python script that will call an external exe file. Code is kind of like this:

This is a perfect example where you can simplify the problem down to a
few lines that fail for you, and actually document the environment and
the results.


#cmd = "D:\\programs\\MIRAX_SlideAC_SDK\\Bin\\MrxSlideExport.exe -s D:\\fit\\projects\\bayer\\KidneyLiver\\MiraxScanner\\Slides\\L10 -e -o D:\\fit\\projects\\bayer\\KidneyLiver\\MiraxScanner\\Output\\L10 -z 5 -f png"
#os.system(cmd)
#msg = os.popen(cmd, mode='r', buffering=-1) # does not work

That's a useless statement. What you really should be saying is: I ran
exactly xxx, and it formatted my neighbor's D: drive. Or you should
skip that, and just concentrate on the ancient os.system() you're asking
about. BTW, any reason you're not using the multiprocess module? It
can simplify a lot of things, for example, bypassing the shell, so you
know what the child program is really getting as parameters.
cmd = cmdForExportingSlicesToTiles + " -s " + slicePath + " -o " + pathToResultData
print(cmd)
os.system(cmd)

So the problem is that is says it doesn't have sufficient memory.

Who says? At what point do they say it? Show us a transcript of
exactly what you do to see this message, and actually show the message.


You probably could simplify this to 5 lines:

import os
cmd = "some literal string with lots of options"
print "About to launch program"
print cmd
os.system(cmd)

Then you run it from the cmd line, and copy/paste the results into your
mnext message.

C:\Somedir\ > python myprog.py
About to launch program
some literal...

Some message that might mention running out of memory...

Naturally, you should specify your Python version, your OS version, and
any other variables you can think of.
 
S

Steven D'Aprano

Hey guys,

I have a python script that will call an external exe file. Code is kind
of like this:

"Kind of like"? So it might be different? How much different?

[snip irrelevant code]

Please try to cut your code down to the minimum necessary to demonstrate
the problem.

#cmd = "D:\\programs\\MIRAX_SlideAC_SDK\\Bin\\MrxSlideExport.exe -s
D:\\fit\\projects\\bayer\\KidneyLiver\\MiraxScanner\\Slides\\L10 -e
-o D:\\fit\\projects\\bayer\\KidneyLiver\\MiraxScanner\\Output\\L10
-z 5 -f png"

You can simplify Windows pathnames by using forward slashes.

#os.system(cmd)
#msg = os.popen(cmd, mode='r', buffering=-1) # does not work
#print(msg)

Of course it does not work. You have commented it out.

# run through slices in given source-path
cmd = cmdForExportingSlicesToTiles + " -s " + slicePath + " -o " +
pathToResultData
print(cmd)
os.system(cmd)

So the problem is that is says it doesn't have sufficient memory.

What says "it" doesn't have sufficient memory? What's "it"? You may have
seen the error, but we haven't. Please COPY AND PASTE the exact error
message, IN FULL, and describe where it comes from:

* is it a Python traceback?

* something printed directly to the terminal but not a traceback?

* Blue Screen of Death?

* a message in a GUI alert?

* something else?


The weired thing is that if I just ran the exe file directly in cmd
console, it's working without any memory problem. I am wondering whether
if it's some kind of python issue limits the memory that we can use??

No.
 
Y

yuyaxuan0

OK...

1."Memory is not enough..." is giving from the exe program.
2. If I run the exe program directly using cmd console, it's working good.
3. I am using Windows 7, 4GB memory python 2.7 the program is a image processing program.
 
R

rusi

OK...

1."Memory is not enough..." is giving from the exe program.
2. If I run the exe program directly using cmd console, it's working good..
3. I am using Windows 7, 4GB memory python 2.7 the program is a image processing program.

It may be good to go thruogh http://sscce.org/
Your earlier data was too long
Now its not self-contained (and not an example)
 
C

Chris Angelico

You can simplify Windows pathnames by using forward slashes.

These paths are being given to an external tool, so I wouldn't
guarantee that forward slashes will work. But you can use a raw string
literal to avoid doubling them all up.

ChrisA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top