@@ -61,7 +61,7 @@ def add_arguments(self, parser):
6161 "--tasks" ,
6262 nargs = "?" ,
6363 type = int ,
64- const = cpus () // 2 ,
64+ const = default_task_threads ,
6565 default = 0 ,
6666 help = f"Number of task runner threads [default={ default_task_threads } ]" ,
6767 )
@@ -90,6 +90,19 @@ def add_arguments(self, parser):
9090 dest = "periodic" ,
9191 help = "Do not schedule periodic tasks" ,
9292 )
93+ parser .add_argument (
94+ "-a" ,
95+ "--address" ,
96+ default = None ,
97+ help = "IP address to bind to [default=`127.0.0.1`]" ,
98+ )
99+ parser .add_argument (
100+ "-p" ,
101+ "--port" ,
102+ type = int ,
103+ default = None ,
104+ help = "Port to listen on [default=8000]" ,
105+ )
93106 parser .add_argument (
94107 "addrport" ,
95108 nargs = "?" ,
@@ -132,6 +145,7 @@ def handle(self, *args, **options):
132145 port = int (p )
133146 if a := os .getenv ("GRANIAN_HOST" ):
134147 address = a
148+
135149 # Then check to see if an address/port was specified on the command line.
136150 if options ["addrport" ].isdigit ():
137151 # If specifying a port (but no address), bind to 0.0.0.0.
@@ -144,6 +158,13 @@ def handle(self, *args, **options):
144158 elif options ["addrport" ]:
145159 address = options ["addrport" ]
146160
161+ # Finally, override with --address/--port if specified. Necessary because
162+ # `serve -k 9000` will start 9000 workers instead of binding to port 9000.
163+ if a := options ["address" ]:
164+ address = a
165+ if p := options ["port" ]:
166+ port = p
167+
147168 reload_paths = []
148169 if path := options ["reload" ].strip ():
149170 reload_paths .append (path )
0 commit comments