OS error 98 tackle already in use is a network-related error message that happens if you’re utilizing a Python-based utility. This article will train you why it occurred and alternative ways to repair your utility.
You can apply what you’ll study to different purposes that present comparable errors throughout connection. With that mentioned, launch your pc, and let’s get you related.
Why Does Oserror Errno 98 Address Already in Use Occurs ?
The oserror errno 98 happens as a result of one other utility in your system is utilizing the port quantity that the present utility desires to make use of. Or, an occasion of the identical program is utilizing the identical port, and it’s working as a background course of.
– Another Application Is Using the Port Number
Different purposes in your pc can use the identical port quantity, both by configuration or by design. The former means you edited the applying configuration to make use of a particular port quantity.
While the latter means, the applying developer hard-coded the port quantity into the applying. In each circumstances, if the applying is lively and working, no different utility can use the identical port quantity.
For instance, MySQL database makes use of port 3306. So, when MySQL is working, different purposes can’t use port 3306 in your system. This consists of one other model of MySQL in your pc. All makes an attempt to begin these purposes utilizing port 3306 will end result in an error.
The similar applies to different port numbers, and it varies relying on the applying.
– An Instance of the Program Is Running in the Background
Instances of the identical program working in the background of your pc will use the identical port quantity. With this, your pc won’t help you begin an lively model of that utility on the identical port. Such is the case of MySQL as detailed in the earlier part, and it’s the identical for many community purposes.
How To Fix an Address That’s in Use?
(*98*)You can repair an tackle that’s in use by killing the cases of Odoo and restarting your utility. Moreover, you may also go for reusing the tackle from the beginning. If nothing else works, killing the method is left because the final possibility.
More options to repair an tackle that’s in use embrace:
- Restart Raspberry Pi
- Move “app.run” into an “if” assertion
- Expose a free port quantity for Docker
- Use an unused port in Colab
- Kill port 80 on Windows
- Update port quantity for Django
– Reuse the Address
The reuse of an tackle is a repair when you have a Python socket program that gained’t begin instantly after shutdown. In your code, use the next after you’ve created the socket and never after calling the “bind()” perform:
|sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)|
– Kill the Process
When you kill a working course of utilizing a port quantity, you possibly can remedy the oserror: [errno 98] tackle already in use Windows error. The similar works for a Linux machine, and we’ll clarify how you are able to do that as effectively. There are two methods to kill a course of on Windows, you should utilize the Task Manager or the command immediate. The following is the way you do it with the Task Manager:
- Identify the problematic course of.
- Launch the Task Manager in your pc (Ctrl + Shift + esc).
- Locate the applying from the “Processes”.
- Right-click on it and click on “End task”
- Launch the applying that’s displaying the “address in use” error, and the error shouldn’t seem.
If that doesn’t work, you should utilize the next course of with the Windows command immediate:
- Launch the command immediate as an administrator.
- Execute the next command and change XXXX with the goal port quantity: “netstat -ano|findstr “PID :XXXX”
- Identify the PID from the output of the earlier step.
- Kill the method utilizing the next: “taskkill /PID XXXX /f”. Where “XXXX” is the PID.
For Linux, use the next:
- Open your terminal
- Type and execute the next command: netstat -tulpn
- Identify the port, the processes, and their identification quantity.
- Type and execute the next command: kill -9 PID. Where PID is the method ID.
– Kill Instances of Odoo and Restart
You can kill cases of Odoo working in the background to resolve oserror: (errno 98) tackle already in use Odoo 14 error. Now, open your terminal and do the next:
- Type the next command, and press the enter key in your keyboard: ps aux | grep odoo
- Use the next when you have Odoo 9 and eight: ps aux | grep openerp
- Identify all of the Odoo cases working in the background.
- Execute the next and change PID with the PID of the Odoo occasion that’s working in the background: sudo kill -9 PID
- Enter your root password and proceed.
- Repeat the earlier step for each Odoo occasion that’s working in the background.
- Restart Odoo.
– Restart Raspberry Pi
You can restart Raspberry Pi to resolve the oserror errno 98 tackle already in use Raspberry Pi error message. If you’re accessing Raspberry Pi from a Graphical User Interface (GUI), do the next to close it down:
- Locate the top-left nook and click on on the Raspberry menu.
- Click on “Logout” and click on on “Reboot” to restart Raspberry Pi
If you favor the terminal, sort “sudo shutdown -r” to restart your Raspberry Pi. After the restart, you’ll begin afresh and the error won’t happen once more.
– Move “app.run” Into an “If” Statement
The conditional execution of “app.run” will remedy the oserror: [errno 98] tackle already in use gunicorn error. This would be the case should you’re working your utility with Gunicorn and never a Flask server. Now, find “app.run” in your code and replace to the next, what follows is how the code works.
|if __name__ == ‘__main__’:
The earlier code works as a result of, behind the scenes, Gunicorn will bind the tackle earlier than importing your utility. The latter calls “app.run” and when this occurs, “app.run” will attempt to begin its server, however Gunicorn is already utilizing that tackle. The earlier code permits Python to run your utility with out the “address in use” error.
– Expose a Free Port Number for Docker
You can expose a free port quantity to repair the oserror: (errno 98) tackle already in use Docker error. To do that, you should utilize any of the next in your terminal to reveal a port earlier than working your Docker Container.
The objective of those instructions is to find out the port that’ll help you run your Docker container with out an error.
- ss tnlp
- netstat tnlp
- lsof -i -P -sTCP:LISTEN
- lsof -P -i:80
The first command, “ss tnlp” will print the TCP sockets, numeric port quantity, listening sockets, and the method that’s utilizing the socket. The similar applies to “netstat tnlp”, though netstat shouldn’t be formally developed, nevertheless it’s an possibility for you.
The third command will listing the community recordsdata, port numbers, and listening TCP protocols. Finally, the final command will examine if port 80 is free.
– Use an Unused Port in Colab
You can use an unused port to resolve oserror: [errno 98] tackle already in use Colab error. With this, you are able to do your Netron visualization with out the “address in use” error. To get began, do the next in the code of your Netron pocket book:
- Import the “portpicker” library.
- Use the next to entry an unused port: port = portpicker.pick_unused_port().
– Kill Port 80 on Windows
The termination of port 80 in your Windows machine will remedy the oserror: [errno 98] tackle already in use port 80 error. To get began, do the next:
- Open the command immediate as an administrator (it’s the “Terminal” in Windows 11).
- Type the next on the command with out quotes: “netstat -a -o -n”
- Look for a course of that’s utilizing port 80 in the “Local Address” listing and notice the PID.
- Type taskkill /f /PID XXXX (the place “XXXX” is the method identification, for instance, 2987).
- Press the enter key in your keyboard.
- Restart the applying that’s throwing the “address in use” error.
– Update Port Number for Django
To remedy the oserror errno 98 tackle already in use Django error, you possibly can replace the port quantity earlier than you begin the server. For instance, should you’re beginning the server on port 8000, change it to port 8001.
This article defined why an tackle is in use and learn how to repair it in completely different Python purposes. The following are the important thing factors from our dialogue:
- A battle in the port quantity results in the “address is already in use” error in Python purposes.
- Two cases of the identical Python community utility can not use the identical tackle.
- To remedy the “address is already in use” error, you possibly can kill the processes utilizing a particular port quantity.
With all the things that we’ve detailed in this text, you should utilize your Python purposes with out an tackle error. Bookmark our article and are available again to it the following time you wish to repair the error.