<div dir="ltr">Hi Laurent,<div>i have attached a Python script that shows the handling of tgis.init() in a subprocess in case location and mapsets change using grass72.</div><div>The following output was generated with this script, it seems to work on my system:</div><div><br></div><div><div>soeren@knecht:~$ python test_tgis.py </div><div>New envrionment: {u'MAPSET': u'PERMANENT', u'GISDBASE': u'/home/soeren/grassdata', u'LOCATION_NAME': u'nc_spm_08_grass7'}</div><div>TGIS init: </div><div> database: /home/soeren/grassdata </div><div> location: nc_spm_08_grass7 </div><div> mapset: PERMANENT</div><div>New envrionment: {u'MAPSET': u'user1', u'GISDBASE': u'/home/soeren/grassdata', u'LOCATION_NAME': u'nc_spm_08_grass7'}</div><div>TGIS init: </div><div> database: /home/soeren/grassdata </div><div> location: nc_spm_08_grass7 </div><div> mapset: user1</div><div>New envrionment: {u'MAPSET': u'PERMANENT', u'GISDBASE': u'/home/soeren/grassdata', u'LOCATION_NAME': u'nc_spm_08'}</div><div>TGIS init: </div><div> database: /home/soeren/grassdata </div><div> location: nc_spm_08 </div><div> mapset: PERMANENT</div><div>New envrionment: {u'MAPSET': u'user1', u'GISDBASE': u'/home/soeren/grassdata', u'LOCATION_NAME': u'nc_spm_08'}</div><div>TGIS init: </div><div> database: /home/soeren/grassdata </div><div> location: nc_spm_08 </div><div> mapset: user1</div></div><div><br></div><div><br></div><div>Best regards</div><div>Soeren</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-09-24 5:32 GMT+02:00 Laurent C. <span dir="ltr"><<a href="mailto:lrntct@gmail.com" target="_blank">lrntct@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Hi Sören,</p>
<p dir="ltr">I followed you suggestion and now each simulation run in its own process using the multiprocessing library. It works well, thanks.<br>
However, there was indeed something strange going on:<br>
The new mapset, location and accessible mapsets were set properly, as seen by the output of g.mapset and g.mapsets<br>
However, the output of ciface.available_mapsets() and therefore core.get_available_temporal_<wbr>mapsets() were not updated after the first simulation, so tgis.init() were failing, not seeing the new current mapset in its own list of available mapsets.</p>
<p dir="ltr">Below was the output of the software:</p>
<p dir="ltr">g.mapset -p<br>
swashes_1d_1000m<br>
g.mapsets -p<br>
Accessible mapsets:<br>
swashes_1d_1000m PERMANENT<br>
ciface.available_mapsets()<br>
['swashes_1d_1000m', 'PERMANENT']<br>
get_available_temporal_<wbr>mapsets()<br>
{'swashes_1d_1000m': ('sqlite', '/home/laurent/grassdata/<wbr>flood_test/swashes_1d_1000m/<wbr>tgis/sqlite.db')}<br>
Starting simulation for configuration file macdo1000.ini...<br>
[...]<br>
g.mapset -p<br>
hull<br>
g.mapsets -p<br>
Accessible mapsets:<br>
hull PERMANENT hull_rain<br>
ciface.available_mapsets()<br>
['swashes_1d_1000m', 'PERMANENT']<br>
get_available_temporal_<wbr>mapsets()<br>
{'swashes_1d_1000m': ('sqlite', '/home/laurent/grassdata/<wbr>flood_test/swashes_1d_1000m/<wbr>tgis/sqlite.db')}<span class=""><br>
ERROR: Unable to execute sql statement. There is no temporal database<br>
connection defined for mapset <hull></span></p>
<p dir="ltr">It seems that tgis.init() is not doing what it is supposed to, according to the documentation:</p>
<p dir="ltr">"Re-run this function in case the following GRASS variables change while the process runs:<br>
- MAPSET<br>
- LOCATION_NAME<br>
- GISDBASE<br>
- TGIS_DISABLE_MAPSET_CHECK<br>
- TGIS_DISABLE_TIMESTAMP_WRITE<br>
"</p>
<p dir="ltr">Thanks again.</p>
<p dir="ltr">Regards,<br>
Laurent</p><div class="HOEnZb"><div class="h5">
<p dir="ltr">2016-09-22 13:52 GMT-05:00 Sören Gebbert <<a href="mailto:soerengebbert@googlemail.com" target="_blank">soerengebbert@googlemail.com</a>><wbr>:<br>
> Hi Laurent,<br>
> the temporal framework was neither tested nor designed to work in a script<br>
> that changes the location while running. I would suggest to run the temporal<br>
> framework related code in a subprocess that is created each time the<br>
> location or mapset changes. Unfortunately i have no other suggestion. <br>
><br>
> However, have you tested your code with grass 7.2 or 7.3? Many improvements<br>
> have been implement in the recent version that would be beneficial to use.<br>
><br>
> Best regards<br>
> Soeren<br>
><br>
> 2016-09-22 2:47 GMT+02:00 Laurent C. <<a href="mailto:lrntct@gmail.com" target="_blank">lrntct@gmail.com</a>>:<br>
>><br>
>> Hello all,<br>
>><br>
>> I've ran into another related issue.<br>
>> One of the goal of running the software outside of GRASS shell is to<br>
>> batch process simulations in various Locations/mapsets.<br>
>><br>
>> I set the GRASS session for each case. The simulation works well for<br>
>> the first case.<br>
>> However when starting the second case, tgis.init() fails with the<br>
>> following error:<br>
>><br>
>> ERROR: Unable to execute sql statement. There is no temporal database<br>
>> connection defined for mapset <hull><br>
>><br>
>> The mapset and location are properly set.<br>
>> If this case is run first, it works well and it's the second one that<br>
>> fail.<br>
>> Running t.connect -c between two cases does not solve the problem.<br>
>> Actually, t.connect -p shows the correct connection parameters, but<br>
>> tgis.init() still fails.<br>
>><br>
>> Regards,<br>
>> Laurent<br>
>><br>
>><br>
>> 2016-09-21 18:27 GMT-05:00 Laurent C. <<a href="mailto:lrntct@gmail.com" target="_blank">lrntct@gmail.com</a>>:<br>
>> > Hi Sören,<br>
>> ><br>
>> > Setting LD_LIBRARY_PATH is working, thanks. But it cannot be set at<br>
>> > run-time, which is not very user-friendly.<br>
>> > I guess this issue is related to the ticket 2424 [1].<br>
>> ><br>
>> > I managed to get it work at run-time by restarting the program with<br>
>> > sys.execv() after setting the path [2], but I find it a bit ugly and<br>
>> > quite verbose to be multi-platform.<br>
>> ><br>
>> > It would be great if an easier option was possible.<br>
>> ><br>
>> > Regards,<br>
>> > Laurent<br>
>> ><br>
>> > [1] <a href="https://trac.osgeo.org/grass/ticket/2424" target="_blank">https://trac.osgeo.org/grass/<wbr>ticket/2424</a><br>
>> > [2]<br>
>> > <a href="http://stackoverflow.com/questions/6543847/setting-ld-library-path-from-inside-python" target="_blank">http://stackoverflow.com/<wbr>questions/6543847/setting-ld-<wbr>library-path-from-inside-<wbr>python</a><br>
>> ><br>
>> ><br>
>> > 2016-09-21 15:40 GMT-05:00 Sören Gebbert <<a href="mailto:soerengebbert@googlemail.com" target="_blank">soerengebbert@googlemail.com</a>><wbr>:<br>
>> >> Hi,<br>
>> >> i think you have to put the GRASS libraries into your LD_LIBRARY_PATH<br>
>> >> so<br>
>> >> that the python wrapper can access them.<br>
>> >><br>
>> >> Best regards<br>
>> >> Soeren<br>
>> >><br>
>> >> 2016-09-21 20:37 GMT+02:00 Laurent C. <<a href="mailto:lrntct@gmail.com" target="_blank">lrntct@gmail.com</a>>:<br>
>> >>><br>
>> >>> Hello all,<br>
>> >>><br>
>> >>> I'm trying to adapt a python module in order for it to be run outside<br>
>> >>> of<br>
>> >>> GRASS.<br>
>> >>> I followed the instructions from the wiki and<br>
>> >>> lib/python/script/setup.py<br>
>> >>><br>
>> >>> gsetup.init() run without error and I can list maps like in the<br>
>> >>> example.<br>
>> >>><br>
>> >>> However, when I try to import the temporal module, I receive this<br>
>> >>> error:<br>
>> >>><br>
>> >>> import grass.temporal as tgis<br>
>> >>> File "/usr/lib/grass70/etc/python/<wbr>grass/temporal/__init__.py", line<br>
>> >>> 1, in <module><br>
>> >>> from core import *<br>
>> >>> File "/usr/lib/grass70/etc/python/<wbr>grass/temporal/core.py", line 38,<br>
>> >>> in <module><br>
>> >>> from c_libraries_interface import *<br>
>> >>> File<br>
>> >>> "/usr/lib/grass70/etc/python/<wbr>grass/temporal/c_libraries_<wbr>interface.py",<br>
>> >>> line 19, in <module><br>
>> >>> import grass.lib.gis as libgis<br>
>> >>> File "/usr/lib/grass70/etc/python/<wbr>grass/lib/gis.py", line 23, in<br>
>> >>> <module><br>
>> >>> _libs["grass_gis.7.0.4"] = load_library("grass_gis.7.0.4"<wbr>)<br>
>> >>> File "/usr/lib/grass70/etc/python/<wbr>grass/lib/ctypes_loader.py", line<br>
>> >>> 55, in load_library<br>
>> >>> return self.load(path)<br>
>> >>> File "/usr/lib/grass70/etc/python/<wbr>grass/lib/ctypes_loader.py", line<br>
>> >>> 71, in load<br>
>> >>> raise ImportError,e<br>
>> >>> ImportError: <a href="http://libgrass_datetime.7.0.4.so" target="_blank">libgrass_datetime.7.0.4.so</a>: cannot open shared object<br>
>> >>> file: No such file or directory<br>
>> >>><br>
>> >>><br>
>> >>> Did I forgot to set-up something or this is a bug?<br>
>> >>><br>
>> >>> Cheers,<br>
>> >>> Laurent<br>
>> >>> ______________________________<wbr>_________________<br>
>> >>> grass-dev mailing list<br>
>> >>> <a href="mailto:grass-dev@lists.osgeo.org" target="_blank">grass-dev@lists.osgeo.org</a><br>
>> >>> <a href="http://lists.osgeo.org/mailman/listinfo/grass-dev" target="_blank">http://lists.osgeo.org/<wbr>mailman/listinfo/grass-dev</a><br>
>> >><br>
>> >><br>
><br>
><br>
</p>
</div></div></blockquote></div><br></div>