#2608: Launching Python script on Windows fails with missing freeze_support
-------------------------+--------------------------------------------------
Reporter: marisn | Owner: grass-dev@…
Type: defect | Status: new
Priority: normal | Milestone:
Component: Python | Version: 7.0.0
Keywords: | Platform: MSWindows Vista
Cpu: Unspecified |
-------------------------+--------------------------------------------------
Launch the following script on Windows:
{{{
from grass.pygrass.modules.shortcuts import raster as r
r.mapcalc("rand0 = round(rand(0,1))", s=True)
r.neighbors(input="rand0", output="count", method="count")
r.mapcalc("rand1 = if (count > 3, 1, null())")
r.mapcalc("rand2 = if (count < 1, 1, null())")
}}}
and observe an error:
{{{
C:\Users\tests\Documents\rand.py
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\GRASS GIS
7.0.0\Python27\lib\multiprocessing\forking.py", line 380, in
main
prepare(preparation_data)
File "C:\Program Files\GRASS GIS
7.0.0\Python27\lib\multiprocessing\forking.py", line 495, in
prepare
'__parents_main__', file, path_name, etc
File "C:\Users\tests\Documents\rand.py", line 2, in
<module>
r.mapcalc("rand0 = round(rand(0,1))", s=True)
File "C:\Program Files\GRASS GIS
7.0.0\etc\python\grass\pygrass\modules\interface\module.py",
line 616, in __call__
return self.run()
File "C:\Program Files\GRASS GIS
7.0.0\etc\python\grass\pygrass\modules\interface\module.py",
line 714, in run
get_msgr().debug(1, self.get_bash())
File "C:\Program Files\GRASS GIS
7.0.0\etc\python\grass\pygrass\messages\__init__.py", line
352, in get_msgr
_instance[0] = Messenger(*args, **kwargs)
File "C:\Program Files\GRASS GIS
7.0.0\etc\python\grass\pygrass\messages\__init__.py", line
175, in __init__
self.start_server()
File "C:\Program Files\GRASS GIS
7.0.0\etc\python\grass\pygrass\messages\__init__.py", line
185, in start_server
self.server.start()
File "C:\Program Files\GRASS GIS
7.0.0\Python27\lib\multiprocessing\process.py", line 130, in
start
self._popen = Popen(self)
File "C:\Program Files\GRASS GIS
7.0.0\Python27\lib\multiprocessing\forking.py", line 258, in
__init__
cmd = get_command_line() + [rhandle]
File "C:\Program Files\GRASS GIS
7.0.0\Python27\lib\multiprocessing\forking.py", line 358, in
get_command_line
is not going to be frozen to produce a Windows executable.''')
RuntimeError:
Attempt to start a new process before the current process
has finished its bootstrapping phase.
This probably means that you are on Windows and you have
forgotten to use the proper idiom in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce a Windows executable.
}}}
--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2608>
GRASS GIS <http://grass.osgeo.org>