Opened 9 years ago

Closed 6 years ago

#2709 closed defect (worksforme)

pyGRASS Module runs twice from interactive Python prompt

Reported by: martinl Owned by:
Priority: major Milestone: 7.6.0
Component: PyGRASS Version: unspecified
Keywords: interactive prompt Cc: grass-dev@…
CPU: Unspecified Platform: Linux

Description

GRASS 7.1.svn (nc_spm_08_grass7):~/bin > python
Python 2.7.10 (default, Jul  1 2015, 10:54:53) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from grass.pygrass.modules import Module
>>> Module('g.extension', flags='a')
List of installed extensions (modules):
r.subdayprecip.design
r.in.proj
v.convert
v.convert.all
Module('g.extension')

Till now, it's OK. Let's launch another module.

>>> Module('r.mask', flags='r')
ERROR: No existing MASK to remove

But we will get also output from the first command again.

List of installed extensions (modules):
r.subdayprecip.design
r.in.proj
v.convert
v.convert.all

and traceback at the end

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/src/grass_trunk/dist.x86_64-unknown-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 526, in __init__
    self.__call__(*args, **kargs)
  File "/opt/src/grass_trunk/dist.x86_64-unknown-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 583, in __call__
    return self.run()
  File "/opt/src/grass_trunk/dist.x86_64-unknown-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 713, in run
    module=self.name, errors=stderr)
  File "/opt/src/grass_trunk/dist.x86_64-unknown-linux-gnu/etc/python/grass/exceptions/__init__.py", line 68, in __init__
    msg = _("Module run %s %s ended with error") % (module, code)
TypeError: unsupported operand type(s) for %: 'Module' and 'tuple'

Change History (12)

comment:1 by neteler, 9 years ago

Milestone: 7.0.17.0.2

Ticket retargeted after 7.0.1 milestone closed

comment:2 by neteler, 8 years ago

Milestone: 7.0.27.0.3

Ticket retargeted after milestone closed

comment:3 by neteler, 8 years ago

Cc: grass-dev@… added

comment:4 by neteler, 8 years ago

Milestone: 7.0.3

Ticket retargeted after milestone closed

comment:5 by neteler, 8 years ago

Milestone: 7.0.4

Ticket retargeted after 7.0.3 milestone closed

comment:6 by neteler, 8 years ago

I just checked and something is pretty wrong:

GRASS 7.1.svn (eu_laea):~ > python
Python 2.7.10 (default, Sep  8 2015, 17:20:17) 
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from grass.pygrass.modules import Module
>>> Module('g.extension', flags='a')
List of installed extensions (modules):
r.skyview
i.segment.hierarchical
Module('g.extension')                 <<== ????

Anyway, now entering the next command from the original report:

>>> Module('r.mask', flags='r')
ERROR: No existing MASK to remove

Description:
 Maintains GRASS Addons extensions in local GRASS installation.
 Downloads and installs extensions from GRASS Addons repository or other source into the local GRASS installation or removes installed extensions.

Keywords:
 general, installation, extensions, addons, download     <<<-- ?????

Usage:
 g.extension [-lcgasdift] extension=name operation=string [url=url]
   [prefix=path] [proxy=proxy[,proxy,...]] [--help] [--verbose] [--quiet]
   [--ui]

Flags:
  -l   List available extensions in the official GRASS GIS Addons repository
[...]
              default: $GRASS_ADDON_BASE
      proxy   Set the proxy with: "http=<value>,ftp=<value>"

ERROR: Options <extension>, <-l>, <-c>, <-g> and <-a> are mutually exclusive

Description:
 Maintains GRASS Addons extensions in local GRASS installation.
[...]

Keywords:
 general, installation, extensions, addons, download

Usage:
 g.extension [-lcgasdift] extension=name operation=string [url=url]
   [prefix=path] [proxy=proxy[,proxy,...]] [--help] [--verbose] [--quiet]
   [--ui]
[...]

... now there is some "ghost process"... finishing in a loop:

[...]
ERROR: Options <extension>, <-l>, <-c>, <-g> and <-a> are mutually exclusive
^CTraceback (most recent call last):
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/scripts/g.extension", line 134, in <module>
    import shutil
  File "/usr/lib64/python2.7/shutil.py", line 5, in <module>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 526, in __init__
    self.__call__(*args, **kargs)
    """
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 583, in __call__
KeyboardInterrupt
    return self.run()
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 713, in run
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 526, in __init__
    module=self.name, errors=stderr)
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/exceptions/__init__.py", line 68, in __init__
        msg = _("Module run %s %s ended with error") % (module, code)
self.__call__(*args, **kargs)
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 583, in __call__
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 583, in __call__
[...]
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 713, in run
    module=self.name, errors=stderr)
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/exceptions/__init__.py", line 68, in __init__
    msg = _("Module run %s %s ended with error") % (module, code)
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 583, in __call__
    return self.run()
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 713, in run
    module=self.name, errors=stderr)
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/exceptions/__init__.py", line 68, in __init__
    msg = _("Module run %s %s ended with error") % (module, code)
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 583, in __call__
    return self.run()
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 713, in run
    module=self.name, errors=stderr)
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/exceptions/__init__.py", line 68, in __init__
    msg = _("Module run %s %s ended with error") % (module, code)
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 583, in __call__
    return self.run()
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 706, in run
    stdout, stderr = self.popen.communicate(input=self.stdin)
  File "/usr/lib64/python2.7/subprocess.py", line 796, in communicate
    self.wait()
  File "/usr/lib64/python2.7/subprocess.py", line 1384, in wait
    pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
  File "/usr/lib64/python2.7/subprocess.py", line 476, in _eintr_retry_call
    return func(*args)
KeyboardInterrupt

in reply to:  6 comment:7 by zarch, 8 years ago

Hi Markus,

Replying to neteler:

GRASS 7.1.svn (eu_laea):~ > python
Python 2.7.10 (default, Sep  8 2015, 17:20:17) 
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from grass.pygrass.modules import Module
>>> Module('g.extension', flags='a')
List of installed extensions (modules):
r.skyview
i.segment.hierarchical
Module('g.extension')                 <<== ????

This is right, things are clearer using ipython:

In [1]: from grass.pygrass.modules import Module

In [2]: Module('g.extension', flags='a')
No extension (module) installed
Out[2]: Module('g.extension')

the python shell does not differentiate between print in stdout/stderr (generate by the execution of module) and the representation of the object. The line Out[2] is returning the instance of the Module class.

If you are bothering by this just save the instance into a variable:

In [3]: gext = Module('g.extension', flags='a')
No extension (module) installed

Anyway, now entering the next command from the original report:

>>> Module('r.mask', flags='r')
ERROR: No existing MASK to remove

[cut]

    msg = _("Module run %s %s ended with error") % (module, code)
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 583, in __call__
    return self.run()
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 706, in run
    stdout, stderr = self.popen.communicate(input=self.stdin)
  File "/usr/lib64/python2.7/subprocess.py", line 796, in communicate
    self.wait()
  File "/usr/lib64/python2.7/subprocess.py", line 1384, in wait
    pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
  File "/usr/lib64/python2.7/subprocess.py", line 476, in _eintr_retry_call
    return func(*args)
KeyboardInterrupt

Ipython does not soffer by this strange behavior and it works well.

In [4]: Module('r.mask', flags='r')
ERROR: No existing MASK to remove
---------------------------------------------------------------------------
CalledModuleError                         Traceback (most recent call last)
<ipython-input-4-217f55a3bd88> in <module>()
----> 1 rmsk = Module('r.mask', flags='r')

/home/pietro/docdat/src/gis/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.pyc in __init__(self, cmd, *args, **kargs)
    524 
    525         if args or kargs:
--> 526             self.__call__(*args, **kargs)
    527         self.__call__.__func__.__doc__ = self.__doc__
    528 

/home/pietro/docdat/src/gis/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.pyc in __call__(self, *args, **kargs)
    581             if self.check_:
    582                 self.check()
--> 583             return self.run()
    584         return self
    585 

/home/pietro/docdat/src/gis/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.pyc in run(self)
    711                 raise CalledModuleError(returncode=self.popen.returncode,
    712                                         code=self.get_bash(),
--> 713                                         module=self.name, errors=stderr)
    714         return self
    715 

CalledModuleError: Module run r.mask r.mask maskcats=* layer=1 -r ended with error
Process ended with non-zero return code 1. See errors in the (error) output.

No idea on why is not working properly in the standard python shell.

Just for the record it is working under python3...

Python 3.5.1 (default, Dec  7 2015, 12:58:09) 
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from grass.pygrass.modules import Module
>>> Module('r.mask', flags='r')
ERROR: No existing MASK to remove
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pietro/docdat/src/gis/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 526, in __init__
    self.__call__(*args, **kargs)
  File "/home/pietro/docdat/src/gis/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 583, in __call__
    return self.run()
  File "/home/pietro/docdat/src/gis/grass71/dist.x86_64-pc-linux-gnu/etc/python/grass/pygrass/modules/interface/module.py", line 713, in run
    module=self.name, errors=stderr)
grass.exceptions.CalledModuleError: Module run r.mask r.mask maskcats=* layer=1 -r ended with error
Process ended with non-zero return code 1. See errors in the (error) output.

comment:8 by martinl, 8 years ago

Milestone: 7.0.47.0.5

comment:9 by neteler, 8 years ago

Milestone: 7.0.57.0.6

comment:10 by neteler, 6 years ago

Milestone: 7.0.67.0.7

comment:11 by martinl, 6 years ago

Milestone: 7.0.77.6.0

Unable to reproduce in G76. Closing. Feel free to reopen if needed.

comment:12 by martinl, 6 years ago

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.