app.run argument handling: added server kwargs (alike create_server), added warning on extra kwargs, made auto_reload explicit argument. Another go at Windows tests
This commit is contained in:
		
							
								
								
									
										23
									
								
								sanic/app.py
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								sanic/app.py
									
									
									
									
									
								
							| @@ -1096,6 +1096,8 @@ class Sanic: | ||||
|         stop_event: Any = None, | ||||
|         register_sys_signals: bool = True, | ||||
|         access_log: Optional[bool] = None, | ||||
|         auto_reload = None, | ||||
|         asyncio_server_kwargs = None, | ||||
|         **kwargs: Any, | ||||
|     ) -> None: | ||||
|         """Run the HTTP Server and listen until keyboard interrupt or term | ||||
| @@ -1126,6 +1128,9 @@ class Sanic: | ||||
|         :type register_sys_signals: bool | ||||
|         :param access_log: Enables writing access logs (slows server) | ||||
|         :type access_log: bool | ||||
|         :param asyncio_server_kwargs: key-value arguments for | ||||
|                                       asyncio/uvloop create_server method | ||||
|         :type asyncio_server_kwargs: dict | ||||
|         :return: Nothing | ||||
|         """ | ||||
|         if "loop" in kwargs: | ||||
| @@ -1135,14 +1140,14 @@ class Sanic: | ||||
|                 "https://sanic.readthedocs.io/en/latest/sanic/deploying.html" | ||||
|                 "#asynchronous-support" | ||||
|             ) | ||||
|  | ||||
|         # Default auto_reload to false | ||||
|         auto_reload = False | ||||
|         # If debug is set, default it to true (unless on windows) | ||||
|         if debug and os.name == "posix": | ||||
|             auto_reload = True | ||||
|         # Allow for overriding either of the defaults | ||||
|         auto_reload = kwargs.get("auto_reload", auto_reload) | ||||
|         if kwargs: | ||||
|             logger.warning(f"Sanic.run ignored arguments {kwargs.keys()}") | ||||
|         if auto_reload is None: | ||||
|             # Default auto_reload to false | ||||
|             auto_reload = False | ||||
|             # If debug is set, default it to true (unless on windows) | ||||
|             if debug and os.name == "posix": | ||||
|                 auto_reload = True | ||||
|  | ||||
|         if sock is None: | ||||
|             host, port = host or "127.0.0.1", port or 8000 | ||||
| @@ -1174,6 +1179,8 @@ class Sanic: | ||||
|             register_sys_signals=register_sys_signals, | ||||
|             auto_reload=auto_reload, | ||||
|         ) | ||||
|         if asyncio_server_kwargs: | ||||
|             server_settings["asyncio_server_kwargs"] = asyncio_server_kwargs | ||||
|  | ||||
|         try: | ||||
|             self.is_running = True | ||||
|   | ||||
| @@ -97,7 +97,7 @@ class SanicTestClient: | ||||
|             server_kwargs = dict( | ||||
|                 host=host or self.host, | ||||
|                 port=self.port, | ||||
|                 reuse_port=True,  # Try to avoid test failures on Windows | ||||
|                 asyncio_server_kwargs=dict(reuse_address=True), | ||||
|                 **server_kwargs, | ||||
|             ) | ||||
|             host, port = host or self.host, self.port | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 L. Kärkkäinen
					L. Kärkkäinen