“Cannot find empty port in range: 7860-7860” means Gradio tried to start its web server on port 7860 and could not. Most often something is already listening there, such as an earlier copy of the same app that never closed, but Gradio raises the same message when its server fails to start for other reasons. The first step is to find out whether anything holds 7860. Port Detective answers that in one search on Windows, and Port Detective Pro can end the old process safely in one click.
This guide explains why the range reads 7860-7860, how to check the port, and the fixes for each cause.
Type 7860 and see the exact process holding it, on Windows.
Get it fromMicrosoft
Why does the error say 7860-7860 instead of a range?
Gradio is the Python library behind many local AI interfaces, including the AUTOMATIC1111 Stable Diffusion WebUI and Fooocus. Its documentation on environment variables lists three that control the port:
| Variable | Default | What it does |
|---|---|---|
GRADIO_SERVER_PORT | 7860 | The port Gradio starts from |
GRADIO_SERVER_NAME | 127.0.0.1 | The network address it binds to |
GRADIO_NUM_PORTS | 100 | How many ports to try when searching |
The behaviour comes from Gradio’s own server code, in gradio/http_server.py. If launch() is called without a server_port, Gradio tries a range starting at GRADIO_SERVER_PORT, 7860 by default, and uses the first free one. If a server_port is passed, the list of ports to try contains only that one port.
When every port in the list fails, Gradio raises this error, quoted from the current source:
OSError: Cannot find empty port in range: 7860-7860. You can specify a different port by setting the GRADIO_SERVER_PORT environment variable or passing the `server_port` parameter to `launch()`.
The message prints the lowest and highest port in the list. In the current source, a fixed port gives 7860-7860, and a fully blocked default search would show 7860-7959. Older Gradio releases were not the same, though: Gradio issue 8730 shows a plain demo.launch() on Gradio 4.x printing 7860-7860. So treat the range as a hint, not proof that a port was fixed.
Notice also what the code catches. A port that is genuinely busy and a server that fails to start for another reason both end in the same message.
What causes the error?
There are two families of cause, and they need different fixes.
Something really is on 7860:
- An earlier run is still alive. You closed the browser tab, but the Python process and its console window are still running, perhaps minimized or hidden behind other windows.
- A crashed run left a process behind. The interface died, but a
python.exeis still holding the socket. - Two Gradio apps want the same port. For example, the WebUI and a second tool both launched on 7860.
- Something unrelated took it. Any program can listen on 7860.
Nothing is on 7860, but the server still failed to start:
- In Gradio issue 8730, the cause was the
nest_asynciopackage patching the event loop. - In Fooocus issue 2296, a user reported the error on first launch with
--port 7860and no other process on the port, and the app worked after a restart. - On Windows, a port inside a range the system has reserved cannot be bound even though no process shows on it.
Checking the port tells you which family you are in, so do that before you change anything.
How do you find the process using port 7860 on Windows?
With built-in tools, open Command Prompt and run:
netstat -ano | findstr :7860
Look for a line in the LISTENING state. The last number is the process ID. Then look it up:
tasklist /FI "PID eq 12345"
Replace 12345 with your PID. In PowerShell, Get-NetTCPConnection -LocalPort 7860 gives the same information, with an OwningProcess column.
That works, but it is two commands and a lookup, and python.exe alone does not tell you which Python program it is. With Port Detective, type 7860 in the search and you see the process name, PID and connection state straight away. Port Detective Pro also shows the executable path and the parent and child lineage, which tells you whether that python.exe belongs to your WebUI’s virtual environment or to something else.
See which python.exe owns 7860, with its path and parent process.
Get it fromMicrosoft
How do you fix it?
If the port check shows a listener, use fix 1 or 2. If it shows nothing, go to fix 4.
Fix 1: close the old copy
If the owner is an earlier run of the same app, close its console window, or end the process:
taskkill /PID 12345
Add /F only if it refuses to close. Before you end a process by PID, confirm the PID is still the one you looked up; Windows can reuse a PID after a process exits. Port Detective Pro checks a secure process token before it terminates anything, so a recycled PID cannot point the kill at the wrong program.
Fix 2: run on a different port
If the other program is supposed to be there, move your app instead.
For a Gradio script you control, pass a port to launch(), for example demo.launch(server_port=7861), or set the variable before you start it:
set GRADIO_SERVER_PORT=7861
In PowerShell, use $env:GRADIO_SERVER_PORT = "7861".
For AUTOMATIC1111, the command line arguments wiki documents --port: it launches Gradio with the given server port, defaults to 7860 if available, and notes that ports below 1024 need administrator rights. Add it to COMMANDLINE_ARGS in webui-user.bat:
set COMMANDLINE_ARGS=--port 7861
Other launchers usually have a similar setting; check their documentation.
Fix 3: let Gradio search
If you wrote the script and do not care which port it uses, remove the fixed server_port. Gradio then searches upward from GRADIO_SERVER_PORT through the number of ports in GRADIO_NUM_PORTS and prints the one it chose in its “Running on local URL” line.
Fix 4: when nothing is on the port
If netstat and Port Detective show no listener on 7860, the problem is not another program. Read the full traceback above the error line, since the real failure is often printed first. Check whether your script or a notebook environment applies nest_asyncio, update Gradio and the app to current versions, and try once more after a restart. If the bind still fails, check whether 7860 falls in a range Windows has reserved; see excluded port ranges.
How do you stop it happening again?
- Close the console, not just the tab. The browser tab is only a client. The server lives in the console window.
- Pin 7860 in Port Detective. Pinned ports stay at the top of the dashboard, so you can see at a glance whether 7860 is free before you launch.
- Use Port Guard for the port you depend on. In Port Detective Pro, Port Guard watches pinned ports from the system tray every 250 milliseconds and shows a Windows notification when something unexpected takes one.
- Give each tool its own port. If you run several Gradio apps, fix each to a different port so they never collide.
Does —listen or 0.0.0.0 change anything?
It changes which network interfaces the app listens on, not the port. The AUTOMATIC1111 wiki says --listen makes the server listen on 0.0.0.0, so other machines on your network can reach it. Gradio’s default GRADIO_SERVER_NAME is 127.0.0.1, which is local only. Either way, if another process already holds 7860 on that address, you get the same error. Only open the server to your network if you mean to.
For a wider view of the same class of error, see EADDRINUSE on Windows and finding the process using a port.
Frequently asked questions
Why does Gradio not just pick another port?
In current Gradio, it searches a range only when server_port is not passed. If a port is fixed, by your script or a launcher flag such as --port, it tries that one port.
Is it safe to end the python.exe on port 7860?
If it is an earlier run of your own app, yes, though you lose anything unsaved in that session. Check the executable path first so you do not end an unrelated Python program.
Which port should I move to?
Any free port above 1024 is fine. 7861 is a common choice. Check it is free first.
Does Port Detective work offline?
Yes. Core features make no external network calls.
Try Port Detective
Port Detective Free is in the Microsoft Store for live TCP and UDP tracking and instant port lookup. Port Detective Pro, a one-time purchase with a free trial in the Microsoft Store, adds one-click termination with process token checks, executable paths, process lineage and Port Guard. The Port Detective product page has the full feature list, and our guide to Ollama on port 11434 covers another local AI port.
Find what holds 7860, end it safely, and keep the port for your WebUI.
Get it fromMicrosoft
Last updated 24 October 2026. Published by Automata Labs, a software company in Canada.