Django manage.py runserver command freezing on OSX - python

I have a few different systems that I use for development of a Django project. The main being Linux, then Windows, and then Mac...all systems implement development using Pycharm
Up until about a week ago I was able to develop my Django project on Mac just fine, I could run the server and check updates as usual, however, for some reason I cannot seem to figure out, the terminal just freezes for about 5 minutes when I run:
python3 manage.py runserver 8000
The server still starts after that 5 minutes but the startup time is quite literally awful, and I do not know what to look at to figure out where the issue is.
I have not changed my code between work and home, just pulled directly from Git and I have the same issues. On my Windows System at home the Django app also runs within a few seconds of starting the server, as does the Linux system at work, so it seems to be only happening on OSX.
Again, I am using Pycharm, but even if I manually enter the project directory and run the server, the startup time is slow
Has anybody run into issues like this, or where can I look to try and find the cause of the error?

Related

how to make your python web app always running on ubuntu machine

I have a web app that I deployed to a machine that has ubuntu 20 installed
to be able to run the app I should open ssh to the ubuntu machine and then run this command
cd mywebapp
python3 app.py
it works successfully, but once I close the ssh console or reboot the machine or anything happens, it stopped and I have to repeat these commands
I tried to add it as a corn job to be run after machine reboot but it does not work
I post a question in the following link : run python app after server restart does not work using crontab
nothing work with me, and I have to make sure that this web app will always be running because it should be working to send push notification to mobile devices
can anyone please advice, I have been searching and trying for so many time
I'm not expert in it, but two solutions come in my mind:
1- Using systemd:
systemd can be responsible to keep services up.
You can write a custom unit for your app, and config it as a way to be up always.
This tutorial may be useful: writing unit
2- Using Docker:
When you have containerized app, you config it as to come up, on failure or anything like that.
Read about it here
What if you have the calling piece of Python script within a bash script and run that as a daemon:
Your bash script could like below (test.sh):
#!/bin/sh
cd desired/directory
python3 app.py
and you can run the bashscript like this by using nohup:
nohup ./test.sh 0<&- &>/dev/null &
You could refer this, if you want to store the outputs of nohup.

python manage.py runserver not working on on localhost:8000

I am new to django and trying to run the django server for the first time. I am trying to run the command for starting a django server in a terminal, i.e. python manage.py runserver. But when I go to http://localhost:8000, it is not giving me the default django output containing a rocket like image.
I even tried using http://my_ip:8000 and http://127.0.0.1:8000 but still it doesn't work. I also tried running the command as python manage.py runserver 8000 but it still does not give me anything on localhost:8000.
I have checked and no firewall / antivirus is blocking this port for me. Also, I am able to access other applications on other ports.
I am not getting any errors on my terminal when I run this command. This is a blocker for me and any help would be really appreciated.
Follow the image of my vs code integrated terminal here
Find my image of browser navigated to http://localhost:8000 over here.
I am using the latest python version 3.9 and my django version is 3.2.
Thanks!

Local Django server cannot connect when run through Bash on Windows

I recently realized that I could use Bash for Windows as the terminal for use in Pycharm so that the IDE had a proper terminal in it even through it was in Windows. I want to work on a Django project but I realized something strange. When I run the server through the IDE's run button, everything runs as expected. However, when I try to run the server through the command line via
python3 manage.py runserver,
the terminal output is the same, but my browsers cannot connect. Instead they say that the connection was reset. I have full installations of Django and Python for both Windows and the Bash environment and both seem to be fully functional. I can make migrations and create new apps through the command line just fine, but I was wondering if anybody else knew why the Django Server does not connect when run through Bash on Windows

Django hangs after trying to init server on OSX El Capitan

I'm trying to run a Django project on OSX El Capitan, MySQL 5.7.9 for OSX 10.9 (no download for 10.11). I'm using a virtual environment. I installed all dependencies using "pip", on that virtual environment. This project works on other machines. The only thing I changed is the local.py file, in order to link the proper database. I'm trying to run the server with the command:
python manage.py runserver 127.0.0.1:9000
When I type that on the main Django directory, the console hangs - there is no error or success message, it just hangs there indefinitely. How can I troubleshot/debug to locate the cause of this problem?
I didn't see #Alasdair comment in time, so I used the ipdb library to trace the program execution. I used:
import ipdb; ipdb.set_trace()
To set a breakpoint on manage.py. I then attempted to run the server again. I used c to navigate to the breakpoint and n to step through the program flow until the program froze. I then repeated that process by using s instead of n on the point the freeze happened. I also updated the breakpoint position sometimes, as not to need to go through the whole execution all over again every time.
After navigating all the way through the Django libs, to my own project model's, back to a Django class's constructors responsible for doing lazy DB queries, I figured it should be a database-related issue. I then downgraded MySQL to version 5.6.27 by installing the .DMG package available the official site. Doing so solved the issue.

How to hide the console when running the django developement server?

I want to run the django developement server localy and I don't want to use a full webserver.
So far I renamed manage.py to manage.pyw. Then in manage.pyw I call execute_from_command_line(['manage.py', 'runserver'])
In a batch file I then use "START pythonw manage.pyw"
The problem is, that I then cannot connect to the server even though in the taskmanager it says it's still running. When I start it using python instead, it runs, but the console window is visible.
I found a way to do this. I used the Windows Service Wrapper https://github.com/kohsuke/winsw to install python manage.py runserver as a service.

Categories