Python [Errno 98] Address already in use
Yes, it is intended. Here you can read detailed explanation. It is possible to override this behavior by setting SO_REUSEADDR option on a socket. For example:
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
OSError: [Errno 98] Address already in use
The best to explain it is to look at example from google. The app.run()
should be only for local testing. The example has following comment:
if __name__ == '__main__':
# This is used when running locally only. When deploying to Google App
# Engine, a webserver process such as Gunicorn will serve the app. This
# can be configured by adding an `entrypoint` to app.yaml.
app.run(host='127.0.0.1', port=8080, debug=True)
So it's enough to add similar if
statement before app.run()
. I have replicated your code on my side and I got same error. After adding the if
statement working fine on app engine. Python OSError: [Errno 98] Address already in use but no port is used
This problem recreates on my side too. From debugging the Flask code, it looks like in debug mode there's no usage of SO_REUSEADDR, so the next attempt to bind with the same address (your tcp server) would fail. One option is to turn off the debug mode:
app.run(debug=False)
Another option is to turn off the reloader (the reloader is good if you're modifying your application while the server is running):app.run(debug=True, use_reloader=False)
socket.error: [Errno 98] Address already in use
I think you are trying to run more than one Odoo server on the same port.
Try this on terminal:
sudo netstat -nlp | grep 8069
then you will see something like this: tcp 0 0 0.0.0.0:8069 0.0.0.0:* LISTEN 10869/python2
Kill the process:sudo kill -9 10869
ORChange the port number in the fileServer.py
.
Then try to start Odoo.
Hope it will help you.
How to fix '[Errno 98] Address already in use' in Python
SO_REUSEADDR
doesn't let you bind two things to the same port at once. Its primary function is to bypass the waiting period after a socket shuts down. If you want to bind two things at once, you need to use something stronger: SO_REUSEPORT
.
Flask make_server always raises OSError: [Errno 98] Address already in use
The problem was that the __init__
method is apparently called for every test, so it was failing at the second one every time.
The solution is to put the creation of the server and the Thread in the setUp method, and close them in the tearDown.
def setUp(self):
self.mock_server = make_server('localhost', 6000, mock_wfm)
self.mock_server_thread = Thread(target = self.mock_server.serve_forever)
self.mock_server_thread.start()
time.sleep(1)
def tearDown(self):
self.mock_server.shutdown()
self.mock_server_thread.join()
Edit:The methods setupClass
and teardownClass
are apparently an even better solution as they are run once per class instead of once per test.
Python socket OSError: [Errno 98] Address already in use
You must use the following statement before using the bind() method
serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)If you still have problems, you can look at your network connections and close the one you used previously manually, for when you run the program again, if you have already put the above-mentioned instruction before the bind() method everything should be fine.
Related Topics
Representing and Solving a Maze Given an Image
Nan Loss When Training Regression Network
How to Get the Version Defined in Setup.Py (Setuptools) in My Package
Python Pandas Dataframe, Is It Pass-By-Value or Pass-By-Reference
How to Read a Response from Python Requests
How to Modify Procfile to Run Gunicorn Process in a Non-Standard Folder on Heroku
Extract Int from String in Pandas
Is There an Platform Independent Equivalent of Os.Startfile()
A Good Way to Make Long Strings Wrap to Newline
Changing the Options of a Optionmenu When Clicking a Button
How to Ignore One Single Specific Line with Pylint
How to Release Memory After Creating Matplotlib Figures
Why Use Sys.Path.Append(Path) Instead of Sys.Path.Insert(1, Path)
Using Only the Db Part of Django
How to Crop an Image Using Pil