Opened 4 years ago

Closed 3 years ago

#16049 closed New feature (duplicate)

Make runserver reuse listening socket

Reported by: dready Owned by: anonymous
Component: Core (Management commands) Version: master
Severity: Normal Keywords:
Cc: jezdez, bhuztez@…, deprince@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When using autoreload mode of runserver, there is a small window of time between restarts that the port is not bound. This disrupts the workflow because one has to wait for the server to come back up before being able to reload the browser to see code changes reflected.

We can reuse the listening socket's file descriptor by having the parent create the socket, and passing it to the child (where the real web server is run.)

A proof-of-concept is available on https://github.com/wil/django-pserver

Change History (11)

comment:1 Changed 4 years ago by dready

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

patch coming up..

comment:2 Changed 4 years ago by jezdez

  • Triage Stage changed from Unreviewed to Accepted

I like the idea but am not sure what the side effects could be, e.g. sockets that are kept open when the server crashes.

comment:3 Changed 4 years ago by dready

Currently when server crashes, we'll have to Ctrl-C to kill the entire process anyway right? It should behave the same way, when the server starts up and crashes, there's not much we can do about it. except to kill it. I agree though, that we should be aware of side effects, can't say I've thought it through. Hopefully we can get some feedback from users of django-pserver.

comment:4 Changed 4 years ago by ed@…

Windows users don't have socked.fromfd() method which is used in the version of django-pserver. - ed

comment:5 follow-up: Changed 4 years ago by dready

Yeah I was planning to specifically test for win32, use hasattr(socket, "fromfd") or try-except, then disable the function accordingly. Ugly, but I can't think of a better way.

comment:6 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:7 in reply to: ↑ 5 Changed 3 years ago by bhuztez

Replying to dready:

Yeah I was planning to specifically test for win32, use hasattr(socket, "fromfd") or try-except, then disable the function accordingly. Ugly, but I can't think of a better way.

Python 3 do have socket.fromfd on Windows. Ridiculously, Issue 1378 got closed without patch actually applied to Python 2. I guess it is better fixed in Python.

http://bugs.python.org/issue1378

comment:8 Changed 3 years ago by bhuztez

  • Cc bhuztez@… added

comment:9 Changed 3 years ago by Adam DePrince <deprince@…>

  • Cc deprince@… added
  • Owner changed from nobody to anonymous
  • Status changed from new to assigned

Is there any objection to making this django feature contingent upon http://bugs.python.org/issue1378 for our windows users?

comment:10 Changed 3 years ago by aaugustin

I'm closing this ticket in favor of #18855 which has a good-looking patch.

comment:11 Changed 3 years ago by aaugustin

  • Resolution set to duplicate
  • Status changed from assigned to closed
Note: See TracTickets for help on using tickets.
Back to Top