run_simple调用的是什么
时间: 2024-03-10 19:47:08 浏览: 24
`run_simple`方法调用的是Python标准库中的`wsgiref.simple_server`模块中的`make_server`函数和`serve_forever`方法。`make_server`函数用于创建一个WSGI服务器,其语法如下:
```python
make_server(host, port, app, server_class=WSGIServer,
handler_class=WSGIRequestHandler, ssl_context=None)
```
其中,`host`和`port`表示服务器的主机名和端口号,`app`表示WSGI应用程序,`server_class`表示服务器类,默认为`WSGIServer`,`handler_class`表示请求处理程序类,默认为`WSGIRequestHandler`,`ssl_context`表示SSL上下文。
`serve_forever`方法用于启动服务器并开始监听请求,其语法如下:
```python
serve_forever(poll_interval=0.5)
```
其中,`poll_interval`表示轮询间隔时间,默认为0.5秒。
因此,`run_simple`方法实际上是使用`wsgiref.simple_server`模块中的`make_server`函数来创建一个WSGI服务器,并使用`serve_forever`方法来启动服务器并开始监听请求。
相关问题
run_simple调用的源码
`run_simple`方法是`werkzeug.serving`模块中提供的一个简单的服务器运行工具,它可以运行一个WSGI应用程序。它的源码如下:
```python
def run_simple(hostname, port, application, use_reloader=False,
use_debugger=False, use_evalex=True, extra_files=None,
reloader_interval=1, reloader_type='auto', threaded=False,
processes=1, request_handler=None, static_files=None,
passthrough_errors=False, ssl_context=None):
if use_debugger:
from werkzeug.debug import DebuggedApplication
application = DebuggedApplication(application, evalex=use_evalex)
if static_files:
from werkzeug.middleware.shared_data import SharedDataMiddleware
application = SharedDataMiddleware(application, static_files)
if request_handler is None:
request_handler = BaseHTTPServer.WSGIRequestHandler
srv = make_server(hostname, port, application, threaded, processes,
request_handler, passthrough_errors, ssl_context)
if use_reloader:
from werkzeug._reloader import run_with_reloader
run_with_reloader(lambda: srv.serve_forever(),
extra_files=extra_files,
interval=reloader_interval,
reloader_type=reloader_type)
else:
srv.serve_forever()
```
该方法的功能主要是创建一个WSGI服务器并运行一个WSGI应用程序。其中,`hostname`和`port`分别表示服务器的主机名和端口号,`application`是一个WSGI应用程序,`use_reloader`和`use_debugger`分别表示是否启用重载器和调试器,`extra_files`表示需要监视的其他文件,`reloader_interval`表示重载器检查文件更改的时间间隔,`reloader_type`表示重载器的类型,`threaded`和`processes`分别表示是否启用多线程和多进程,`request_handler`表示请求处理程序,`static_files`表示静态文件的路径,`passthrough_errors`表示是否将错误传递给WSGI应用程序,`ssl_context`表示SSL上下文。
如果`use_reloader`为True,则使用`werkzeug._reloader`模块中的`run_with_reloader`函数来启动重载器。如果`use_debugger`为True,则使用`werkzeug.debug`模块中的`DebuggedApplication`类来启动调试器。如果`static_files`不为None,则使用`werkzeug.middleware.shared_data`模块中的`SharedDataMiddleware`类来处理静态文件。最后,使用`make_server`函数创建一个WSGI服务器,并通过`serve_forever`方法来运行服务器。
TypeError: run_simple() got an unexpected keyword argument 'prot'
TypeError: run_simple() got an unexpected keyword argument 'prot' 是一个错误提示,意味着在调用run_simple()函数时传入了一个未预期的关键字参数'prot'。这个错误通常发生在使用Flask框架时,run_simple()函数是Flask中的一个函数,用于运行开发服务器。
根据错误提示,'prot'参数是未预期的,可能是拼写错误或者不正确的参数名。请检查代码中调用run_simple()函数的地方,确保传入的参数名正确。
如果你能提供更多的上下文或代码片段,我可以给出更具体的帮助。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)