As per Murtuza, we will have the '__module__', when running as a WSGI

application, but - it will not have the '__file__' attribute.
This commit is contained in:
Ashesh Vashi 2017-04-03 18:55:21 +05:30
parent b756407c3c
commit 02a3919b06

View File

@ -113,9 +113,17 @@ class ServerType(object):
)) ))
) )
bin_path = self.utility_path.get() bin_path = self.utility_path.get()
# AS WSGI application, we will not find the '__main__' module. if "$DIR" in bin_path:
if "__main__" in sys.modules: # When running as an WSGI application, we will not find the
bin_path = bin_path.replace("$DIR", os.path.dirname(sys.modules['__main__'].__file__)) # '__file__' attribute for the '__main__' module.
main_module_file = getattr(
sys.modules['__main__'], '__file__', None
)
if main_module_file is None:
bin_path = bin_path.replace(
"$DIR", os.path.dirname(main_module_file)
)
return os.path.abspath(os.path.join( return os.path.abspath(os.path.join(
bin_path, bin_path,