Skip to content

Commit

Permalink
Added exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
smanga24 committed Dec 13, 2024
1 parent 1d34a82 commit 8035596
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,29 @@
def initialize_debugpy():
import debugpy

if not os.getenv("RUN_MAIN"):
try:
debugpy.listen(("0.0.0.0", 5678))
sys.stdout.write("debugpy listening on port 5678...\n")
except Exception as exc:
sys.stderr.write(f"Failed to initialize debugpy: {exc}\n")


def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.prod")

try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
raise
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == "__main__":
ENABLE_DEBUGPY = os.getenv("ENABLE_DEBUGPY")
print("DEBUGPY: ", ENABLE_DEBUGPY)
if ENABLE_DEBUGPY and ENABLE_DEBUGPY.lower() == "true":
initialize_debugpy()
main()
Expand Down

0 comments on commit 8035596

Please sign in to comment.