Skip to content

DuplicateFlagError when module with gflags definition is reimported #9

@GoogleCodeExporter

Description

@GoogleCodeExporter
A DuplicateFlagError is thrown when:
1) Module A imports the gflags module and defines gflags.
2) Module A imports B
3) Module B imports A

Example:

File main.py:
---------------------------------
#!/usr/bin/python2.6

import sys
import gflags
import dep   # error

FLAGS = gflags.FLAGS
gflags.DEFINE_boolean("example", True, "example_flag")

if __name__ == "__main__":
  FLAGS(sys.argv)
  print FLAGS.example

---------------------------------


File dep.py:
---------------------------------
#!/usr/bin/python2.6

import main
---------------------------------


Error output:
---------------------------------
Traceback (most recent call last):
  File "example\main.py", line 10, in <module>
    gflags.DEFINE_boolean("example", True, "example_flag")
  File "C:\gflags\python\gflags.py", line 2378, in DEFINE_boolean
    DEFINE_flag(BooleanFlag(name, default, help, **args), flag_values)
  File "C:\gflags\python\gflags.py", line 2190, in DEFINE_flag
    fv[flag.name] = flag
  File "C:\gflags\python\gflags.py", line 1040, in __setitem__
    raise DuplicateFlagError(name, self)
gflags.DuplicateFlagError: The flag 'example' is defined twice. First from 
main, Second from example\main.py

Original issue reported on code.google.com by linshu...@google.com on 26 Mar 2012 at 7:11

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions