[GRASS-dev] [GRASS GIS] #2134: Create a general exit-safe interface to C libraries
GRASS GIS
trac at osgeo.org
Fri Nov 22 18:06:03 PST 2013
#2134: Create a general exit-safe interface to C libraries
--------------------------------------------------+-------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Python ctypes | Version: svn-trunk
Keywords: G_fatal_error, exit, multiprocessing | Platform: All
Cpu: Unspecified |
--------------------------------------------------+-------------------------
Comment(by zarch):
Replying to wenzeslaus:
Replying to huhabla:
I am not sure if i understand your approach, so code examples would be
very helpful here. :)
My original idea does not involved RCP server, it was about ctypes calls
versus module calls. It would require rewrite the whole pyGRASS using
modules. Here is sample pseudo code:
(IMHO) I don't see the point to make a python API using the modules
interface. It will be only slow and useless for any real task, already
pygrass for some operations it consume too much memory (probably it is due
to some circular references, that need to be solve...) or is too slow.
off-topic { Personally if I have to do the effort of rewriting pygrass I
would use Cython (or CPython), moreover I think that we should work to
reduce and clean the high redundancy of the code, a lot of Python objects
and functions are duplicate between script/pygrass/temporal/wxgui simply
using slightly different logic and this is unmaintainable, unfortunately I
have not the global view of the ~111000 rows (removing blank lines and
comments) of the code. But I do think that we should work on that
direction. }
Why not simply define your function (containing ctypes or ctypes-based
function/objects) and call through the RPC interface? In this way, from my
little understanding of the problem, you should be able to preserve the
GUI from a crash, avoiding at the same time to make another duplicate,
don't you?
Something like (not tested):
{{{
from grass.pygrass.vector import VectorTopo
from grass.pygrass.vector.geometry import Point
from grass.pygrass.function import get_mapset_vector
def add_points(vname, vmapset='', *points):
"""
>>> add_points('new', (1, 2), (2, 3), (3, 4))
"""
mapset = get_mapset_vector(vname, vmapset) # chek if already exist
with VectorTopo(vname, mapset, mode='rw' if mapset else 'w') as vct:
for x, y in points:
vct.write(Point(x, y))
ciface = RPCServer()
check = ciface.call(function=add_points, args=('new', (1, 2), (2, 3), (3,
4)))
}}}
--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2134#comment:13>
GRASS GIS <http://grass.osgeo.org>
More information about the grass-dev
mailing list