Today We are Going To Solve Python [Errno 98] Address already in use in Python. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.
How to Fix Python [Errno 98] Address already in use Error?
- How to Fix Python [Errno 98] Address already in use Error?
To Fix Python [Errno 98] Address already in use Error just Set SO_REUSEADDR option on a socket. Here you have to just set SO_REUSEADDR option on a socket. You can see this in my below example. I hope this will help you.
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- Python [Errno 98] Address already in use
To Fix Python [Errno 98] Address already in use Error just Run the command. To solve this error just run the below commands: Bash:
kill -9 $(ps -A | grep python | awk '{print $1}')
Fish:kill -9 (ps -A | grep python | awk '{print $1}')
Solution 1 : Set SO_REUSEADDR option on a socket
Here you have to just set SO_REUSEADDR option on a socket. You can see this in my below example. I hope this will help you.
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Solution 2 : Run the command
To solve this error just run the below commands:
Bash:
kill -9 $(ps -A | grep python | awk '{print $1}')
Fish:
kill -9 (ps -A | grep python | awk '{print $1}')
Conclusion
So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.
Also Read These Solutions
- Python socket.: [Errno 104] Connection reset by peer
- Element implicitly has an ‘any’ type because expression of type ‘string’ can’t be used to index type ‘{}’
- TypeError: Cannot read properties of undefined (reading ‘id’) in Angular
- SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated UXXXXXXXX escape
- Uncaught (in promise) DOMException: play() failed because the user didn’t interact with the document first
Hi, everyone!
My installation method is via deb package. And I follow this link to install.
https://github.com/NVIDIA/DIGITS/blob/master/docs/UbuntuInstall.md
But when type ‘sudo ./digits-devserver -c’ after installed , I get some errors:
- modprobe: FATAL: Module nvidia not found.
cudaRuntimeGetVersion() failed with error fixed passing of incorrect sizes #38
(I use the CPU-ONLY model, because the graphic card can’t support CUDA in my computer )
2.socket.error: [Errno 98] Address already in use: (‘0.0.0.0’, 5000)
My digit vision is 3.0.3.
The next section is return.
Thanks .
fzy@fzy-OptiPlex-3020:/usr/share/digits$ sudo ./digits-devserver -c
================================ Jobs Directory ================================
Where would you like to store job data?
Suggested values:
(*) [Previous] /usr/share/digits/digits/jobs
(D) [default] /usr/share/digits/digits/jobs
>>
Using "/usr/share/digits/digits/jobs"
modprobe: FATAL: Module nvidia not found.
cudaRuntimeGetVersion() failed with error #38
=================================== Log File ===================================
Where do you want the log files to be stored?
Suggested values:
(*) [Previous] /var/log/digits/digits.log
(S) [System] /var/log/digits/digits.log
(D) [default] /usr/share/digits/digits/digits.log
(N) [none] <NONE>
>>
Using "/var/log/digits/digits.log"
==================================== Caffe =====================================
Where is caffe installed?
Suggested values:
(*) [Previous] <PATHS>
(P) [PATH/PYTHONPATH] <PATHS>
>>
Using "<PATHS>"
==================================== Torch =====================================
Where is torch installed?
Suggested values:
(*) [Previous] <PATHS>
(P) [PATH/TORCHPATH] <PATHS>
(N) [none] <NONE>
>>
Using "<PATHS>"
___ ___ ___ ___ _____ ___
| _ _/ __|_ _|_ _/ __|
| |) | | (_ || | | | __
|___/______|___| |_| |___/ 3.0.0-rc.3
* Running on http://0.0.0.0:5000/
Traceback (most recent call last):
File "./digits-devserver", line 58, in <module>
policy_server=False
File "/usr/lib/python2.7/dist-packages/flask_socketio/__init__.py", line 414, in run
self.server.serve_forever()
File "/usr/lib/python2.7/dist-packages/gevent/baseserver.py", line 282, in serve_forever
self.start()
File "/usr/lib/python2.7/dist-packages/gevent/baseserver.py", line 234, in start
self.init_socket()
File "/usr/lib/python2.7/dist-packages/gevent/pywsgi.py", line 639, in init_socket
StreamServer.init_socket(self)
File "/usr/lib/python2.7/dist-packages/gevent/server.py", line 78, in init_socket
self.socket = self.get_listener(self.address, self.backlog, self.family)
File "/usr/lib/python2.7/dist-packages/gevent/server.py", line 89, in get_listener
return _tcp_listener(address, backlog=backlog, reuse_addr=self.reuse_addr, family=family)
File "/usr/lib/python2.7/dist-packages/gevent/server.py", line 153, in _tcp_listener
sock.bind(address)
File "<string>", line 1, in bind
socket.error: [Errno 98] Address already in use: ('0.0.0.0', 5000)
cerr
-
#1
Hi There,
I get a socket error «[Errno 98] Address already in use» when i try to
open a socket that got closed before with close(). How come close()
doesn’t close the socket properly?
My socket code :
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(1)
….
….
….
while loop:
conn, addr = s.accept()
while conn and loop:
….
….
….
conn.close()
Shouldn’t that clean it all up properly?
Thanks for hints & suggestions!
Ron
Advertisements
Thomas Jollans
-
#2
Hi There,
I get a socket error «[Errno 98] Address already in use» when i try to
open a socket that got closed before with close(). How come close()
doesn’t close the socket properly?
My socket code :s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(1)
…
…
…
while loop:
conn, addr = s.accept()
while conn and loop:
…
…
…
conn.close()Shouldn’t that clean it all up properly?
`s` is still listening?
jipalaciosortega
-
#3
——BEGIN PGP SIGNED MESSAGE——
Hash: SHA1
El 15/09/2010 20:58, Grant Edwards escribió:
I get a socket error «[Errno 98] Address already in use» when i
try to open a socket that got closed before with close(). How
come close() doesn’t close the socket properly? My socket code :s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port)) s.listen(1) … … … while loop: conn,
addr = s.accept() while conn and loop: … … … conn.close()At what line does the error occur?
To what does the phrase «open a socket» refer?
Have you tried the usual solution of setting the SO_REUSEADDR
option on the socket before calling bind?http://www.google.com/search?q=socket+’address+already+in+use’
Maybe, you have any other proccess in your system using your listen
port, for example apache…
— —
_ _ _ _ _ _ _ _ _ _ _
Jose Ignacio Palacios Ortega /_ _/ / / / _ / / _ /
Telf: +34 637 058 813 / / / / / /_ / / / / / /
Correo-e: (e-mail address removed) _ / / / / / _ _ _/ / / / /
Msn: (e-mail address removed) / /_ / / / / / / / /_/ /
ID firma PGP: 0x0EB87E48 _ _ / /_/ /_/ /_ _ _/
Huella PGP:61CC 5DA0 827B C3AB F83C 2A55 78AF B317 0EB8 7E48
——BEGIN PGP SIGNATURE——
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla — http://enigmail.mozdev.org/
iEYEARECAAYFAkyRafgACgkQeK+zFw64fkjH2wCffe4v8ho2z4d8LWaPaiJRu0OZ
4cgAniOoR70hu7UylkpgAr3JI5hxNXYP
=MoYK
——END PGP SIGNATURE——
cerr
-
#4
——BEGIN PGP SIGNED MESSAGE——
Hash: SHA1El 15/09/2010 20:58, Grant Edwards escribió:
I get a socket error «[Errno 98] Address already in use» when i
try to open a socket that got closed before with close(). How
come close() doesn’t close the socket properly? My socket code :
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port)) s.listen(1) … … … while loop: conn,
addr = s.accept() while conn and loop: … … … conn.close()At what line does the error occur?
To what does the phrase «open a socket» refer?
Have you tried the usual solution of setting the SO_REUSEADDR
option on the socket before calling bind?Maybe, you have any other proccess in your system using your listen
port, for example apache…
Nope negative, I have one process on my system only that occupies port
1514.
cerr
-
#5
I get a socket error «[Errno 98] Address already in use» when i try to
open a socket that got closed before with close(). How come close()
doesn’t close the socket properly?
My socket code :s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(1)
…
…
…
while loop:
conn, addr = s.accept()
while conn and loop:
…
…
…
conn.close()At what line does the error occur?
The whole message I get looks like:
Traceback (most recent call last):
File «./checkGPIO.py», line 148, in <module>
main()
File «./checkGPIO.py», line 75, in main
s.bind((host, port))
File «<string>», line 1, in bind
socket.error: [Errno 98] Address already in use
Where line 75 contains following:
s.bind((host, port))
To what does the phrase «open a socket» refer?
create a listening socket…?
Have you tried the usual solution of setting the SO_REUSEADDR option
on the socket before calling bind?
yep, that did it for me, thanks a lot!
Google’s your friend if you can read
björn lundin
-
#6
Where line 75 contains following:
s.bind((host, port))
As Tomas pointed out, you close conn, but you do not close the server
socket ‘s’
/Björn
Advertisements
Lawrence D’Oliveiro
-
#7
In message
cerr said:
I get a socket error «[Errno 98] Address already in use» when i try to
open a socket that got closed before with close(). How come close()
doesn’t close the socket properly?
The usual case this happens is you have a client connection open at the
time, that was not properly terminated. Then the TCP stack goes through a
holdoff period (2 minutes, I believe it is), to make absolutely sure all
packets destined for the old connection have completely disappeared off the
entire Internet, before it will let you open a socket on the same port
again.
Grant Edwards
-
#8
In message
cerr said:
I get a socket error «[Errno 98] Address already in use» when i try to
open a socket that got closed before with close(). How come close()
doesn’t close the socket properly?The usual case this happens is you have a client connection open at the
time, that was not properly terminated. Then the TCP stack goes through a
holdoff period (2 minutes, I believe it is), to make absolutely sure all
packets destined for the old connection have completely disappeared off the
entire Internet, before it will let you open a socket on the same port
again.
Even when the connection was properly terminated (from an
application’s POV), there’s a TIME_WAIT period before the TCP stack
considered the connection completely gone and will allow re-use of the
port. IOW, the TIME_WAIT is actually part of the connection
termination (from the TCP stack’s POV), and it can takes place after
the application considers the connection closed (and may have even
exited):
http://www.developerweb.net/forum/showthread.php?t=2941
Lawrence D’Oliveiro
-
#9
Even when the connection was properly terminated (from an
application’s POV), there’s a TIME_WAIT period before the TCP stack
considered the connection completely gone and will allow re-use of the
port.
I’m not so sure about that. I’ve done a bunch of development on a system
recently which had a server process written in Python running on a Linux
box, accepting connections from a client running under old MacOS 9 (don’t
ask) which was, of course, prone to crash.
If the client had shut down cleanly, then I could stop and restart the
server process without any problems reopening the socket. But if I forgot to
close the client, then the server would hit the “already in use†error.
To deal with it, I simply put in an automatic retry at 60-second intervals
until it succeeded in reopening the socket.
Jorgen Grahn
-
#10
In message
cerr said:
I get a socket error «[Errno 98] Address already in use» when i try to
open a socket that got closed before with close(). How come close()
doesn’t close the socket properly?The usual case this happens is you have a client connection open at the
time, that was not properly terminated. Then the TCP stack goes through a
holdoff period (2 minutes, I believe it is), to make absolutely sure all
packets destined for the old connection have completely disappeared off the
entire Internet, before it will let you open a socket on the same port
again.
That’s why Stevens recommends that all TCP servers use the
SO_REUSEADDR socket option. He also noted in his book:
«This scenario is one of the most frequently asked
questions on Usenet.»
Possibly I missed something in the question, but it’s worth googling for.
/Jorgen
Lawrence D’Oliveiro
-
#11
Jorgen Grahn said:
That’s why Stevens recommends that all TCP servers use the
SO_REUSEADDR socket option.
I don’t think I’ve ever used that. It seems to defeat a safety mechanism
which was put in for a reason.
Advertisements
Nobody
-
#12
I don’t think I’ve ever used that. It seems to defeat a safety mechanism
which was put in for a reason.
It was put in for the benefit of clients, to prevent them from selecting
a port which they won’t be able to use. At the point that the program
calls bind(), the kernel doesn’t know whether the program will call
connect() or listen() next (i.e. whether it’s a client or a server).
Even if you set SO_REUSEADDR, you cannot create a connection which could
be confused with an existing connection, i.e. one with the same source and
destination address and port (BSD allows this provided that the previous
connection is closed and the initial sequence number of the new connection
exceeds the final sequence number of the previous connection).
For a client, re-using the port would mean that any attempt to connect to
the same port and address as an existing TIME_WAIT connection will fail
with EADDRINUSE, so it should choose another port. This scenario is quite
likely, as a client for a particular protocol will tend to connect to a
specific remote port, and often to a small set of servers.
But a server often has to use a specific port, and its clients will
typically connect from ephemeral ports. Even if some clients insist on
trying to use a specific source port (which will fail so long as the
TIME_WAIT connections exist), the server can still serve other clients.
Lawrence D’Oliveiro
-
#13
It was put in for the benefit of clients, to prevent them from selecting
a port which they won’t be able to use.
But clients typically don’t care what port they use—they let the system pick
a port for them, so this kind of option is unnecessary.
Nobody
-
#14
But clients typically don’t care what port they use—they let the
system pick a port for them, so this kind of option is unnecessary.
If they use an ephemeral port, the kernel won’t pick a port which has any
connections in the TIME_WAIT state.
However, some clients choose their own source ports. E.g. rlogin/rsh use
privileged (low-numbered) ports, and you can’t get the kernel to choose a
random privileged port for you.
If you’re writing a server which listens on a known port, you *should* be
using SO_REUSEADDR to avoid unnecessary delays in start-up. The kernel
will automatically reject packets relating to stale connections, and your
server should be accepting any new connections ASAP.
Lawrence D’Oliveiro
-
#15
However, some clients choose their own source ports. E.g. rlogin/rsh use
privileged (low-numbered) ports, and you can’t get the kernel to choose a
random privileged port for you.
But nobody uses rlogin/rsh any more, and who would attach any trustworthy
meaning to a connection coming from a remote low-numbered source port?
If you’re writing a server which listens on a known port, you *should* be
using SO_REUSEADDR to avoid unnecessary delays in start-up. The kernel
will automatically reject packets relating to stale connections, and your
server should be accepting any new connections ASAP.
That makes it sound like SO_REUSEADDR should really be a superfluous option.
But it’s not.
Advertisements
Nobody
-
#16
But nobody uses rlogin/rsh any more,
They did when the bind() and SO_REUSEADDR semantics were developed. If
they were doing it now, chances are that SO_REUSEADDR would be enabled by
default.
and who would attach any trustworthy
meaning to a connection coming from a remote low-numbered source port?
If you receive a connection with a low-numbered source port and it
*isn’t* legitimate, then someone has got root (in which case any other
authentication mechanism isn’t safe either) or someone has hijacked the
IP address (you do know that low-numbered ports are only meaningful for
systems under your control, right?).
Using a firewall rule which only allows connections from a low port on
specific IP addresses certainly isn’t any worse than a rule which only
allows connections from any port on specific IP addresses. That’s true
regardless of whether the protocol includes other authentication
mechanisms.
That makes it sound like SO_REUSEADDR should really be a superfluous option.
But it’s not.
Well it is mostly superfluous. It should always be enabled for a server
listening on a known port, and doesn’t matter for a client which uses
ephemeral ports.