Hi I just started working with Pelican and it really suits my needs, I had tried to build blogs in Flask and other frameworks but I really just wanted something simple so I can post about math, and pelican just works.
My question is when I am testing on my machine, I start the server; however when I stop the server to make some edits to my test blogs, and then try to reload the server I get a socket already in use error. I am stopping my server by ctrl+z am I doing this correctly?
Use ctrl+c to terminate the process. ctrl+z will only send it's execution to the background.
On a separate note, since you are making changes and want to test them it would be more convenient to use $ make devserver instead of $ make serve. See docs.
For your development server, you can also use the script ./develop_server.sh that comes with the last versions of pelican (at least with the 3.5.0).
Build the blog and load a server with ./develop_server.sh start: it reloads each time you edit your blog (except the settings). Simply stop with ./develop_server.sh stop when you're finished.
When you press Ctrl + C or Ctrl + z, do not restart the HTTP server: it is running in the background, and that is the exact reason as why you are getting that error message.
To see that the server is running in the background after pressing the any of the key combinations above, try to edit and save any file: you will see right away in the terminal the re-generation process of your pages is active again.
You can start the HTTP server using this command: make devserver and stop by ./developer_server.sh stop
Related
I am trying to create a web application using flask. I have already gotten somewhat comfortable with using python, and have done so using spyder, inside of Anacanda Navigator. Now I am playing around with flask doing basic functions and have successful so far by testing it out in local server 127.0.0.1:5000. The problem I am having is that I cannot stop the server once I run the script in spyder. I have stopped the script and run other scripts through the console, but the local server remains the same.
The reason this is a problem for me is because when I try to change files and run a different flask script, the server does not update with the new information. For example, if I run a flask script that returns "Hello World" on the main page, and then I stop that file, open a new file that has a different flask script that returns "The sky is blue" the server does not change when I check it on chrome or any other browser. It will onyl return "Hello World"
I have been able to fix this problem by completely restarting my computer, but I am wondering if there is another way, just to restart the local server, 127.0.0.1:5000. Thank You!
Also I am using windows
I do : "Run > Configuration per file > Execute in an external system terminal",
then when you run your .py containing the app.run, it will be launched in an external console. If you close the console the server will be closed too.
To Kill the local server, you may use Ctrl+C command and not any other command. This command is also mentioned when the server is up and running.
I've been having this precise issue and have been smashing my head against the wall for a couple of hours. I posted the referenced StackOverflow question (my first actually) and it seems that running a script from inside Spyder is the wrong way to go as it leaves runaway background processes running, even after restarting Spyder.
I got the recommendation to only launch my *.py code from the command prompt. Furthermore I was told to do this:
set FLASK_APP=main1.py then set FLASK_DEBUG=1 then flask run
though I'm not sure what that does, so I will investigate. I was about to restart my computer as a last ditch effort until I looked in my Windows Task Manager and found some Python tasks running. After [end task] them both I was able to launch the updated webpage on my local host.
I'm working on a simple Flask web application. I use Eclipse/Pydev. When I'm working on the app, I have to restart this app very often because of code changes. And that's the problem. When I run the app, I can see the frame on my localhost, which is good. But when I want to close this app, just click on the red square which should stop applications in Eclipse, sometimes (often), the old version of application keeps running so I can't test the new version. In this case the only thing which helps is to force close every process in Windows Task Manager.
Will you give me any advice how to manage this problem? Thank you in advance.
EDIT: This maybe helps: Many times, I have to run the app twice. Otherwise I can't connect.
I've faced the same problem and solved it. I think it may help.
When we run a flask based site locally it is assigned to a TCP port: 5000 and the Default IP: 127.0.0.1:5000
Sometimes TCP connection remains even after closing the program or terminating the code. So, The idea is kill the TCP connection. You can do it from command-prompt(cmd)
Two Steps to Follow:
1. See the Process ID(PID) for the running TCP connection.
Go to cmd and type:
netstat -ano
Kill The Process By PID. Command for this: taskkill /f /im [PID]. Example is showed bellow.
taskkill /f /im 7332
I've had a very similar thing happen to me. I was using CherryPy rather than Flask, but my solution might still work for you. Oftentimes browsers save webpages locally so that they don't have to re-download them every time the website is visited. This is called caching, and although it's very useful for the average web user, it can be a real pain to app developers. If you're frequently generating new versions of the application, it's possible that your browser is displaying an old version of the app that it has cached instead of the most up to date version. I recommend clearing that cache every time you restart your application, or disabling the cache altogether.
This actually shouldn't happen with the latest versions of PyDev (i.e.: since PyDev 3.4.1: http://pydev.org/history_pydev.html, PyDev should kill all the subprocesses of the main process).
So, can you check which PyDev version are you using?
If you're in the latest version of PyDev, you can use Ctrl+Shift+F9 to terminate/relaunch by default.
But as you're dealing with flask, you should be able to use it to reload automatically on code-changes without doing anything by setting use_reloader=True.
I.e.: I haven't actually tested, but its documentation says that you can set the reload flag for that run(use_reloader=True) -- and PyDev should even be able to debug it (I'll take a better look and improve the PyDev docs on that area later on).
I don't want to run tornado in debug mode or use autoreload , still I want to be able to reload the server by a trigger , like requesting a specific url, or with a timer or something,
Is there a way to manually reload a tornado httpserver without killing the process and starting it again?
The only way I have done this is to run it behind a Nginx proxy and then restart each running process through supervisord. It's kind of clunky, but once you script it out it's not that bad actually and should be transparent to the user.
Just did a search and found a very similar but better worded answer:
Is there a way to deploy new code with Tornado/Python without restarting the server?
I recently started developing Django using Pydev in Eclipse, along with several other people I know, and I keep losing several hours of productivity a day to this error that I can't seem to debug. Essentially, sometimes after starting up my django run configuration, I'll go to the URL http://127.0.0.1:8000/foo and it simply spits me back this response:
<h1>Page not found: /foo</h1>
At first I could reproduce this behavior all the time; any time I had multiple workspaces of eclipse open and shut down my Django server once, the server wouldn't actually shut down, but it would just keep serving the page not founds until I shut down both instances of Eclipse.
Stopping doing that and it seemed to work, but then it intermittently seemed to start back up again. When this happens, it will literally not stop happening until I close eclipse, and the eclipse.exe process will hang (and continue to server Page not found pages) until I manually go into the process and kill it. Sometimes, that won't even fix it, and it'll break itself the first time I try to start Django back up.
I'm on the stable build of PyDev and Eclipse 3.6.1.
Any idea what's going on? This is unbelievable frustrating, especially because I tend to like the IDE with this exception.
Are you by any chance using a run configuration to launch your development server? Because that kept happening to me too. It seems that eclipse isn't cleanly closing django when you stop it from the IDE and it's holding on to the http port. In that sense you're sending requests to a zombie server instance, hence the not founds. I have since resorted to launching django from the command line. Not the prettiest solution, I admit.
I asked this question on superuser, but haven't gotten a response. Maybe here would of been more appropriate.
When I start my redis server with redis-server, even after I close the terminal or logout the process will still be there when I log back in, but my python bottle server python server.py will turn off if I close to terminal or logout. How do I get similar behavior as redis in python.
The easy way is to run the process through screen or tmux.
You could also try doing something with e.g. python-daemon on Unix, or various other approaches for running daemons.