EXTERNAL: OSError: [Errno 48] Address already in use
none at invalid.com
Wed Jul 4 13:41:00 EDT 2018
On 02/07/2018 18:51, T Berger wrote:
> On Monday, July 2, 2018 at 1:22:59 PM UTC-4, T Berger wrote:
>> On Saturday, June 30, 2018 at 6:02:06 PM UTC-4, T Berger wrote:
>>> On Friday, June 29, 2018 at 7:00:15 PM UTC-4, Cameron Simpson wrote:
>>>> The key point here from Jim is "simultaneously". Are you properly shutting down
>>>> the Flask instance in IDLE before running from Terminal, and vice versa?
>>> Cameron, I try every option to quit either program, but they don't work. Or I should say, they mostly don't work. Once in a while they do. The one option which works (which is not a feasible option) is rebooting my Mac (actually that might not work either. I think I got the error message again this morning when I rebooted).
>>>> Otherwise both will try to use the same local port and There Can Be Only One.
>>>> Do you need to run from both environments at the same time? I'd have thought
>>>> not, which also leads me to: why are you flicking from IDLE to Terminal? I
>>>> would have imagined using one or the other normally, not both. It isn't wrong
>>>> to use both, just surprising.
>>> I'm working from a Python manual. I created the webapp in IDLE, and test it in Terminal, per the instructions in the manual. I use IDLE to edit my program, and then test it in terminal. When I go from one to the other, I get the error message. IDLE has a keyboard shortcut for quitting the shell—Cntl + C—but it doesn't work. Neither does restarting the shell. Neither does entering the kill command line, not in IDLE or terminal.
>>> Do you have any other suggestions? I'm going to email the writer. He doesn't mention how to deal with problems that might arise from working with two programs at the same time. Maybe Cntl+C should do it, but in my case it doesn't.
>> Cameron, I'd like to add screenshots of my idle and terminal windows. Perhaps this would shed light on my this issue.
>> This is my last window in terminal:
>> [Restored Jul 2, 2018, 1:12:09 PM]
>> Last login: Mon Jul 2 10:58:54 on ttys000
>> Restored session: Mon Jul 2 11:04:19 EDT 2018
>> 192:Webapp TamaraB$ exit
>> Saving session...
>> ...saving history...truncating history files...
>> [Process completed]
>> To me this looks like the program running in terminal has been killed.
>> Now this is my idle shell:
>> RESTART: /Users/TamaraB/Desktop/Webapp/vsearch4web.py
>> * Serving Flask app "vsearch4web" (lazy loading)
>> * Environment: production
>> [31m WARNING: Do not use the development server in a production environment. [0m
>> [2m Use a production WSGI server instead. [0m
>> * Debug mode: on
>> Traceback (most recent call last):
>> File "/Users/TamaraB/Desktop/Webapp/vsearch4web.py", line 26, in <module>
>> File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 943, in run
>> run_simple(host, port, self, **options)
>> File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/werkzeug/serving.py", line 795, in run_simple
>> s.bind(get_sockaddr(hostname, port, address_family))
>> OSError: [Errno 48] Address already in use
>> Why should there be an error in idle? It's the only app running.
>> I emailed the writer of the manual I'm using, but who knows if, or when, he'll reply. So any help you provide would be great.
> I forgot to add that I get the error message even after I exit from idle. Exiting from idle is supposed to kill the running program. That is what the the confirming dialog box explicitly states.
Tamara, read something on how TCP sockets work. Even if you close the
program that created the socket, it doesn't mean the port in use will
close immediately. It all depends on the state the socket was in. There
is a process of exchanging info that sockets go through when closing to
make sure both ends know the socket has closed. This can take time to
complete. ISTR the default is 120secs.
You can get past the wait by ensuring you close the socket when no
connections are pending. Then you can use that port immediately. If
there is something active on the socket, closing the socket puts you
into TIME_WAIT and you cannot rebind to that socket till the timeout is
Or you can set SO_REUSEADDR on the socket after you create it but before
you use it. This allows another program to immediately use the port as
soon as you call close on the socket. Only 1 program can use the port
still, but this option allows you to bypass the wait state.
This info has already been given in this thread but maybe you missed it
or maybe didn't understand it.
Please read up some general background information on sockets
programming because it will make your programming life easier when you
know what is meant to happen.
More information about the Python-list