Access changed gflag value

279 views Asked by At

I have two (2) scripts as follows:

test.py

from google.apputils import app
import gflags

FLAGS = gflags.FLAGS
gflags.DEFINE_string('flag1', 'Value 1', 'flag#1')

def main(argv):
    FLAGS.flag1 = "Value2"
    print 'Flag 1 has value: ' + FLAGS.flag1

if __name__ == '__main__':
    app.run()

and test1.py

from google.apputils import app
import test

def main(argv):
    print 'Flag 1 has value: ' + test.FLAGS.flag1


if __name__ == '__main__':
    app.run()

How I can pass changed flag value from test.py to test1.py so I have output "Flag 1 has value: Value2" in test1.py?

1

There are 1 answers

0
jaskowitchious On

I have found the solution as follows:

test.py

from google.apputils import app
import subprocess


def main(argv):
    entry = raw_input("Enter Value: ")
    subprocess.Popen('python test1.py --flag1="' + entry + '"', shell=True)


if __name__ == '__main__':
    app.run()

and test1.py

from google.apputils import app
import gflags

gflags.DEFINE_string('flag1', None, 'Flag#1')

FLAGS = gflags.FLAGS


def main(argv):
    print 'Flag 1 has value: ' + FLAGS.flag1


if __name__ == '__main__':
    app.run()