引言

还是老样子,想研究源码,从最新版看没有太大的意义,最好是从第一个版本v0.1开始看起,因为东西最少,但是涉及到的整个框架的设计思路是基本上不会变的···

文章目录

  • 一些概念
    • flask
    • werkzeug
    • wsgi
    • web server /web application
  • 简单了解werkzeug
  • 开始了解flask
    • 快速开发一个hello,world应用
    • 源码分析
      • 实例化过程
      • run源码阅读
      • run_simple源码阅读
      • serve_forever阅读源码
  • 本回合总结

一些概念

flask

这是对flask的最初始的描述

A microframework based on Werkzeug.  It's extensively documented
and follows best practice patterns.
>>> 翻译过来就是
一个基于werkzeug的微型框架,有大量的文档以及遵循最佳设计实践

werkzeug

前面说flask是基于werkzurg进行的实现,那么这个werkzeug是个什么鬼呢?

解释: Werkzeug是一个WSGI工具包,他可以作为一个Web框架的底层库

wsgi

那么什么又是WSGI呢?

解释:Web Server Gateway Interface,它由Python标准定义的一套Web Server与Web Application的接口交互规范,WSGI不是一个应用、框架、模块或者库,而是规范

web server /web application

说到这里又要解释一下什么是web serverweb application
举例来说,例如常见的web application有Django、Flask等,而web server有uWSGI、Gunicorn等。WSGI就是定义了这两端接口交互的规范

简单了解werkzeug

一个原生的基于WSGI 的 “Hello World” 应用看起来是这样的:

# 底层提供两个变量(请求数据需要的环境对象environ,一个可调用的start_response),名字可以改,但是一般不建议
def application(environ, start_response):start_response('200 OK', [('Content-Type', 'text/plain')])return ['Hello World!']

使用werkzeug模块的响应对象,修改如下

from werkzeug.wrappers import Responsedef application(environ, start_response):response = Response('Hello World!', mimetype='text/plain')return response(environ, start_response)

这里有一个在 URL 中查询字符串的扩展版本(重点是 URL 中的 name 将会替代 World)

from werkzeug.wrappers import Request, Responsedef application(environ, start_response):request = Request(environ)text = 'Hello %s!' % request.args.get('name', 'World')response = Response(text, mimetype='text/plain')return response(environ, start_response)

这里我们基于Werkzeug启动一个简单的服务器应用,是不是和flask的服务器创建过程比较像了

from werkzeug.wrappers import Request, Response@Request.application
def application(request):return Response('Hello, World!')if __name__ == '__main__':from werkzeug.serving import run_simplerun_simple('localhost', 8080, application)

开始了解flask

官方的讲,flask是一个轻量级框架, 理解上来说,flask属于跑在web服务器中的一个应用,此应用可以让其和服务器进行交互。

快速开发一个hello,world应用

使用Flask开发一个只返回’hello,world’的简单应用

from flask import Flaskapp = Flask(__name__)@app.route('/')
def hello():return 'Hello, World!'if __name__ == '__main__':app.run()

运行脚本,打开网页, 访问"http://127.0.0.1:5000/ ",即可看到"hello,world"出现,是不是很简单

源码分析

实例化过程

那么这个应用是怎么完成简单几行代码启动了一个服务器的?

首先,实例化对象,Flask类只有一个必须指定的参数,即程序主模块或者包的名字,__name__是系统变量,该变量指的是本py文件的文件名

from flask import Flaskapp = Flask(__name__)

然后,我们浏览下Flask的 __init__逻辑,有些参数我用中文重新注释了

class Flask(object):"""The flask object implements a WSGI application and acts as the centralobject.  It is passed the name of the module or package of theapplication.  Once it is created it will act as a central registry forthe view functions, the URL rules, template configuration and much more.The name of the package is used to resolve resources from inside thepackage or the folder the module is contained in depending on if thepackage parameter resolves to an actual python package (a folder withan `__init__.py` file inside) or a standard module (just a `.py` file).For more information about resource loading, see :func:`open_resource`.Usually you create a :class:`Flask` instance in your main module orin the `__init__.py` file of your package like this::from flask import Flaskapp = Flask(__name__)"""#: the class that is used for request objects.  See :class:`~flask.request`#: for more information.request_class = Request#: the class that is used for response objects.  See#: :class:`~flask.Response` for more information.response_class = Response#: path for the static files.  If you don't want to use static files#: you can set this value to `None` in which case no URL rule is added#: and the development server will no longer serve any static files.static_path = '/static'#: if a secret key is set, cryptographic components can use this to#: sign cookies and other things.  Set this to a complex random value#: when you want to use the secure cookie for instance.secret_key = None#: The secure cookie uses this for the name of the session cookiesession_cookie_name = 'session'#: options that are passed directly to the Jinja2 environmentjinja_options = dict(autoescape=True,extensions=['jinja2.ext.autoescape', 'jinja2.ext.with_'])def __init__(self, package_name):# 是否开启debug模式self.debug = False# 包名或者模块名,唯一需要的必传参数self.package_name = package_name#: 获取app所在目录self.root_path = _get_package_path(self.package_name)# 存储视图函数的字典,键为函数别名,值为函数对象self.view_functions = {}#: a dictionary of all registered error handlers.  The key is#: be the error code as integer, the value the function that#: should handle that error.#: To register a error handler, use the :meth:`errorhandler`#: decorator.self.error_handlers = {}# 处理请求前执行的函数列表,使用@before_request装饰器进行注册self.before_request_funcs = []# 处理请求前执行的函数列表,使用@after_request装饰器进行注册self.after_request_funcs = []#: a list of functions that are called without arguments#: to populate the template context.  Each returns a dictionary#: that the template context is updated with.#: To register a function here, use the :meth:`context_processor`#: decorator.# 上下文相关self.template_context_processors = [_default_template_ctx_processor]# 存储路由和视图函数的映射关系: Map([<Rule '/static/<filename>' (OPTIONS, HEAD, GET) -> 						static>]) 这种格式self.url_map = Map()# 将静态文件路径添加到self.url_map中if self.static_path is not None:self.url_map.add(Rule(self.static_path + '/<filename>',build_only=True, endpoint='static'))if pkg_resources is not None:target = (self.package_name, 'static')else:target = os.path.join(self.root_path, 'static')self.wsgi_app = SharedDataMiddleware(self.wsgi_app, {self.static_path: target})#: the Jinja2 environment.  It is created from the#: :attr:`jinja_options` and the loader that is returned#: by the :meth:`create_jinja_loader` function.# 初始化 Jinja2 模版环境self.jinja_env = Environment(loader=self.create_jinja_loader(),**self.jinja_options)self.jinja_env.globals.update(url_for=url_for,get_flashed_messages=get_flashed_messages)

总结来看,初始化通过传入的包名,解析包内部资源,并注册路由到映射表中,初始化jinja2环境信息,初始化一些可能会用到的额外参数,比如请求钱需要使用的函数列表等等

run源码阅读

这里先不说路由是怎么回事,先来看看这段代码做了什么事情

if __name__ == '__main__':app.run()

这段代码就是第一个版本的run函数,行数非常之少,下面的英文解释一下:

开启本地开发服务器,如果设置debug参数为True,则服务器会在检测到代码变动时自动重启服务器,如果检测到有异常发生,那么将会抛出异常

host,port就是服务器地址和端口号,options是给werkzeug的run_simple使用的,调用底层库实现交互

def run(self, host='localhost', port=5000, **options):"""Runs the application on a local development server.  If the:attr:`debug` flag is set the server will automatically reloadfor code changes and show a debugger in case an exception happened.:param host: the hostname to listen on.  set this to ``'0.0.0.0'``to have the server available externally as well.:param port: the port of the webserver:param options: the options to be forwarded to the underlyingWerkzeug server.  See :func:`werkzeug.run_simple`for more information."""from werkzeug import run_simpleif 'debug' in options:self.debug = options.pop('debug')options.setdefault('use_reloader', self.debug)options.setdefault('use_debugger', self.debug)return run_simple(host, port, self, **options)

run_simple源码阅读

这个flask的run封装了run_simple函数,所以我们要研究下run_simple函数的实现,参数大多数都是给内部核心函数inner.make_server()准备的

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,
):""":param hostname: The host to bind to, for example ``'localhost'``.If the value is a path that starts with ``unix://`` it will bindto a Unix socket instead of a TCP socket..:param port: The port for the server.  eg: ``8080``:param application: the WSGI application to execute:param use_reloader: should the server automatically restart the pythonprocess if modules were changed?:param use_debugger: should the werkzeug debugging system be used?:param use_evalex: should the exception evaluation feature be enabled?:param extra_files: a list of files the reloader should watchadditionally to the modules.  For example configurationfiles.:param reloader_interval: the interval for the reloader in seconds.:param reloader_type: the type of reloader to use.  The default isauto detection.  Valid values are ``'stat'`` and``'watchdog'``. See :ref:`reloader` for moreinformation.:param threaded: should the process handle each request in a separatethread?:param processes: if greater than 1 then handle each request in a new processup to this maximum number of concurrent processes.:param request_handler: optional parameter that can be used to replacethe default one.  You can use this to replace itwith a different:class:`~BaseHTTPServer.BaseHTTPRequestHandler`subclass.:param static_files: a list or dict of paths for static files.  This worksexactly like :class:`SharedDataMiddleware`, it's actuallyjust wrapping the application in that middleware beforeserving.:param passthrough_errors: set this to `True` to disable the error catching.This means that the server will die on errors butit can be useful to hook debuggers in (pdb etc.):param ssl_context: an SSL context for the connection. Either an:class:`ssl.SSLContext`, a tuple in the form``(cert_file, pkey_file)``, the string ``'adhoc'`` ifthe server should automatically create one, or ``None``to disable SSL (which is the default)."""if not isinstance(port, int):raise TypeError("port must be an integer")if use_debugger:from .debug import DebuggedApplicationapplication = DebuggedApplication(application, use_evalex)if static_files:from .middleware.shared_data import SharedDataMiddlewareapplication = SharedDataMiddleware(application, static_files)def log_startup(sock):display_hostname = hostname if hostname not in ("", "*") else "localhost"quit_msg = "(Press CTRL+C to quit)"if sock.family == af_unix:_log("info", " * Running on %s %s", display_hostname, quit_msg)else:if ":" in display_hostname:display_hostname = "[%s]" % display_hostnameport = sock.getsockname()[1]_log("info"," * Running on %s://%s:%d/ %s","http" if ssl_context is None else "https",display_hostname,port,quit_msg,)def inner():try:fd = int(os.environ["WERKZEUG_SERVER_FD"])except (LookupError, ValueError):fd = Nonesrv = make_server(hostname,port,application,threaded,processes,request_handler,passthrough_errors,ssl_context,fd=fd,)if fd is None:log_startup(srv.socket)srv.serve_forever()if use_reloader:# If we're not running already in the subprocess that is the# reloader we want to open up a socket early to make sure the# port is actually available.if not is_running_from_reloader():if port == 0 and not can_open_by_fd:raise ValueError("Cannot bind to a random port with enabled ""reloader if the Python interpreter does ""not support socket opening by fd.")# Create and destroy a socket so that any exceptions are# raised before we spawn a separate Python interpreter and# lose this ability.address_family = select_address_family(hostname, port)server_address = get_sockaddr(hostname, port, address_family)s = socket.socket(address_family, socket.SOCK_STREAM)s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)s.bind(server_address)if hasattr(s, "set_inheritable"):s.set_inheritable(True)# If we can open the socket by file descriptor, then we can just# reuse this one and our socket will survive the restarts.if can_open_by_fd:os.environ["WERKZEUG_SERVER_FD"] = str(s.fileno())s.listen(LISTEN_QUEUE)log_startup(s)else:s.close()if address_family == af_unix:_log("info", "Unlinking %s" % server_address)os.unlink(server_address)# Do not use relative imports, otherwise "python -m werkzeug.serving"# breaks.from ._reloader import run_with_reloaderrun_with_reloader(inner, extra_files, reloader_interval, reloader_type)else:inner()

make_server源码阅读

在这个函数中,make_server()会根据线程或者进程的数量创建对应的WSGI服务器。Flask在默认情况下是创建BaseWSGIServer服务器

def make_server(host=None,port=None,app=None,threaded=False,processes=1,request_handler=None,passthrough_errors=False,ssl_context=None,fd=None,
):"""Create a new server instance that is either threaded, or forksor just processes one request after another."""if threaded and processes > 1:raise ValueError("cannot have a multithreaded and multi process server.")elif threaded:return ThreadedWSGIServer(host, port, app, request_handler, passthrough_errors, ssl_context, fd=fd)elif processes > 1:return ForkingWSGIServer(host,port,app,processes,request_handler,passthrough_errors,ssl_context,fd=fd,)else:return BaseWSGIServer(host, port, app, request_handler, passthrough_errors, ssl_context, fd=fd)

从源码可以看得出来,一共有几种WSGI服务器,基类是BaseWSGIServer,其余服务器类继承自基类,(而基类则是封装了HTTPServer类,)并且同时继承不同的混入类,增加其需要的方法

class BaseWSGIServer(HTTPServer, object):"""Simple single-threaded, single-process WSGI server."""multithread = Falsemultiprocess = Falserequest_queue_size = LISTEN_QUEUEdef __init__(self,host,port,app,handler=None,passthrough_errors=False,ssl_context=None,fd=None,):if handler is None:handler = WSGIRequestHandlerself.address_family = select_address_family(host, port)if fd is not None:real_sock = socket.fromfd(fd, self.address_family, socket.SOCK_STREAM)port = 0server_address = get_sockaddr(host, int(port), self.address_family)# remove socket file if it already existsif self.address_family == af_unix and os.path.exists(server_address):os.unlink(server_address)HTTPServer.__init__(self, server_address, handler)self.app = appself.passthrough_errors = passthrough_errorsself.shutdown_signal = Falseself.host = hostself.port = self.socket.getsockname()[1]# Patch in the original socket.if fd is not None:self.socket.close()self.socket = real_sockself.server_address = self.socket.getsockname()if ssl_context is not None:if isinstance(ssl_context, tuple):ssl_context = load_ssl_context(*ssl_context)if ssl_context == "adhoc":ssl_context = generate_adhoc_ssl_context()# If we are on Python 2 the return value from socket.fromfd# is an internal socket object but what we need for ssl wrap# is the wrapper around it :(sock = self.socketif PY2 and not isinstance(sock, socket.socket):sock = socket.socket(sock.family, sock.type, sock.proto, sock)self.socket = ssl_context.wrap_socket(sock, server_side=True)self.ssl_context = ssl_contextelse:self.ssl_context = Nonedef ···class ThreadedWSGIServer(ThreadingMixIn, BaseWSGIServer):"""A WSGI server that does threading."""multithread = Truedaemon_threads = Trueclass ForkingWSGIServer(ForkingMixIn, BaseWSGIServer):"""A WSGI server that does forking."""multiprocess = Truedef __init__(self,host,port,app,processes=40,handler=None,passthrough_errors=False,ssl_context=None,fd=None,):if not can_fork:raise ValueError("Your platform does not support forking.")BaseWSGIServer.__init__(self, host, port, app, handler, passthrough_errors, ssl_context, fd)self.max_children = processes

serve_forever阅读源码

inner中根据不同情况下返回的服务器类,进行服务器的启动函数,可以看到最终是使用HTTPServer中的启动服务的方法。而HTTPServerPython标准类库中的接口

def serve_forever(self):self.shutdown_signal = Falsetry:HTTPServer.serve_forever(self)except KeyboardInterrupt:passfinally:self.server_close()

本回合总结

初步了解了Flask框架所涉及到的术语及基本的网路协议

通过阅读源码一步步的了解了Flask的服务器启动过程

查看全文
如若内容造成侵权/违法违规/事实不符,请联系编程学习网邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

相关文章

  1. JAVA基础——泛型和容器类7_27

    创建HashMap对象,初始化,替换,遍历的三种方式//创建HashMap对象Map<Integer,String> map1=new HashMap <>();map1.put(001, "Andy");map1.put(001,"Cintry");//key不可以重复,value可以重复map1.put(002,"Smith");System.out.pr…...

    2024/4/10 13:24:16
  2. listagg Oracle ,根据条件汇总某些字段,多行字段合并

    我们的某些业务需要做汇总处理目标:现状:程序处理比较麻烦,这时候oracle listagg 函数就帮上忙了。可以参考一下使用方法:SELECTxzmc "cityName",listagg ( address, , ) within GROUP ( ORDER BY xzmc ) "roadList" FROMZHXT_GD_YDSJLB GROUP BYxzm…...

    2024/4/28 14:19:07
  3. 操作系统中程序的内存结构说明

    一个程序在内存上由BSS段、data段、text段三个组成的。在没有调入内存前,可执行程序分为代码段、数据区和未初始化数据区三部分。 BSS段:(bss segment)通常是指用来存放程序中未初始化的全局变量的一块内存区域。BSS是英文Block Started by Symbol的简称。BSS段属于静态内存…...

    2024/4/28 15:55:26
  4. Java学习-MySQL数据库

    Java学习-MySQL数据库1.基础1.1MySQL数据库在MAC电脑上的安装1.2 数据基本概念1.3 MySQL的一些基本操作2.数据库的基本操作2.1 DDL:操作数据库、表 (CRUD)2.1.1 操作数据库2.2.2 操作表2.2 DML(增删改表中的数据)2.3 DQL:查询表中的记录2.3.1 基础查询2.3.2 排序查询2.3.3 聚…...

    2024/4/27 22:48:56
  5. ShellEOF说明,Expect详解

    文章目录一、EOF说明cat和eof结合使用具有追加功能二、Expect概述三、基本命令四、Expect语法单一分支语法多分支模式语法五、Expect执行方式直接执行嵌入执行案例一:创建用户tom,密码tom123**案例二:SSH登录案例三:FTP登录 前言 一、EOF说明 ● Shell中通常将EOF与 <<…...

    2024/4/26 13:10:58
  6. 快速分析竞争对手的店铺的方法有哪些?

    "强者生存,弱者淘汰,它是大自然的生存之道,一样适用如今市场竞争激烈的电商行业。 怎样锁定自身的竞争者,并迅速地对竞争者开展剖析,随后在剖析后制订有关的对决对策,在经营店面的全过程中就至关重要。 假如连自身都不清楚自身的店面和市场定位,那麼你要沒有宣战就…...

    2024/4/10 13:24:11
  7. cmd命令大全

    CMD命令:开始->运行->键入cmd或command(在命令行里可以看到系统版本、文件系统版本) chcp 修改默认字符集 chcp 936默认中文 chcp 65001 1. appwiz.cpl:程序和功能 2. calc:启动计算器 5. chkdsk.exe:Chkdsk磁盘检查(管理员身份运行命令提示符) 6. cleanmgr: …...

    2024/4/19 9:17:40
  8. Spring 常见注解原理和自定义@interface注解

    一、认识注解 注解(Annotation)很重要,未来的开发模式都是基于注解的,JPA是基于注解的,Spring2.5以上都是基于注解的,Hibernate3.x以后也是基于注解的,现在的Struts2有一部分也是基于注解的了,注解是一种趋势,现在已经有不少的人开始用注解了,注解是JDK1.5之后才有的新…...

    2024/4/21 4:46:12
  9. 获取最长不重复子串

    def get_longest_substr1(s):"""暴力破解1.获取全部不重复子串2.按长度,降序,取第一个:param s::return:"""length = len(s)non_repeats = [(len(s[x:y+1]), s[x:y+1]) for x in range(length) for y in range(x, length) if len(s[x:y+1]) ==…...

    2024/4/26 18:09:33
  10. 网站上线后可以修改哪些内容

    公司网站上线后,有时客户会由于公司原因而需要正价或者减少网站的内容。可是一些公司会担心网站建成后修改网站会不会带来不好的效果?用户会不会找不到公司网站了?网站上线后可以修改哪些内容?事实上,只要网站的大框架不动,是可以修改一些图片和文字什么的。接下来,跟着…...

    2024/4/25 3:32:50
  11. 机器学习(part3)--机器学习与数据挖掘的区别

    学习笔记,仅供参考,有错必纠机器学习与数据挖掘的区别机器学习的定义目前被广泛采用的机器学习的定义是“利用经验来 改善计算机系统自身的性能”。由于“经验”在计算机系统中主要是以数据的形式存在的,因此机器学习需要运用机器学习技术对数据进行分析.数据挖掘的定义所谓…...

    2024/4/10 13:24:08
  12. 05.类、对象、构造方法

    第 1章 面向对象思想 1.1 面向对象思想概述 概述 Java语言是一种面向对象的程序设计语言,而面向对象思想是一种程序设计思想,我们在面向对象思想的指引下,使用Java语言去设计、开发计算机程序。 这里的对象泛指现实中一切事物,每种事物都具备自己的属性和行为。面向对象思…...

    2024/4/10 13:24:07
  13. sqlserver:链接服务器和同义词

    环境:window 10 x64 sqlserver2014 x64参考: Sqlserver 链接服务器和同义词 链接服务器(数据库引擎) 同义词(数据库引擎) 一、链接服务器 1.1 概念 通过链接服务器,你可以从远程数据源中读取或更新数据。 比如说,我们在服务器A上新建链接服务器,让他们分别指向服务器B…...

    2024/4/26 20:32:14
  14. 全媒体环境下高校思想政治教育的嬗变

    高校思想政治教育是学校党建的重要组成部分,是大学生健康成长的重要环节,是培养中国特色社会主义接班人的根本保障。全媒体时代的到来对高校思想政治教育既带来机会也提出挑战。大学生具有接受新鲜事物快、彰显个性自由、民主意识日益增强等特点,是新媒体最直接的受益者、体…...

    2024/4/26 17:21:34
  15. Style2Paints V3 / V4.5 风格迁移上色-软件使用教程

    版权声明: 未经同意,禁止转载。(更新时间:2020-07-28)1. 风格迁移上色教程(如何使用Style2paints进行风格迁移?)1.1 Style2paints V3操作说明目前GitHub仓库内公开的代码和模型为Style2paints V3。虽然V3主要专注于基于颜色提示的线稿上色,但基于风格迁移的线稿上色功…...

    2024/4/22 20:55:26
  16. 第十二章 Logstash入门

    一、概念介绍Logstash是一个类似实时流水线的开源数据传输引擎,它像一个两头连接不 同数据源的数据传输管道,将数据实时地从一个数据源传输到另一个数据源中。在数据传输的过程中,Logstash还可以对数据进行清洗、加工和整理,使数据在 到达目的地时直接可用或接近可用,为更…...

    2024/4/10 13:24:03
  17. PubChem的Python接口PubChemPy使用心得

    花了一整天琢磨PubChemPy这个接口,写一下自己的使用心得:目的:根据化合物名称批量下载化合物的smi格式参考资料:1. https://pubchempy.readthedocs.io/en/latest/2. https://github.com/mcs07/PubChemPy3. https://blog.csdn.net/u012325865/article/details/77148242 原文…...

    2024/4/20 9:41:18
  18. 微信小程序使用swiper和scroll-view做Tab标签页

    说白了,就是利用轮播图的特性做Tab标签页Page({data: {//顶部安全距离(状态栏高度)statusBarHeight: wx.getSystemInfoSync().statusBarHeight,navScrollLeft: 0,currentTab: 0,navData: [{text: A},{text: B},{text: C},{text: D},],},onLoad: function () {},switchNav(ev…...

    2024/4/22 15:24:12
  19. 什么是数据结构与算法

    数据结构,简单说就是数据的存放方式,不同的数据结构不过是数据的存放方式不一样,这里为了方便大家理解,我们用图书馆存放图书来举例,图书馆中的图书就是我们计算机中的数据。我们去图书馆会发现,图书馆一般存储图书是把相同类别的图书存放到一起,或者按照图书名字的首字…...

    2024/4/10 13:24:00
  20. Laravel ENV—— 环境变量的加载与源码解析

    laravel 在启动时,会加载项目的 env 文件,本文将会详细介绍 env 文件的使用与源码的分析。 ENV 文件的使用 多环境 ENV 文件的设置 laravel 支持在不同的环境下加载不同的 env 文件,若想要实现多环境 env 文件,需要做两件事: 一、在项目写多个 ENV 文件,例如三个 env 文件…...

    2024/4/10 13:23:59

最新文章

  1. Pytorch GPU版本安装

    一、背景 记录一下安装Pytorch GPU版本过程。 由于手残&#xff0c;卸载了电脑上的显卡驱动&#xff0c;现在我连显卡类型是啥都不知道了。 总体思路&#xff1a;安装显卡驱动->安装cuda->安装pytorch库 二、安装显卡驱动 2.1 查看本地显卡型号 通过「DirectX 诊断工具…...

    2024/4/28 17:10:10
  2. 梯度消失和梯度爆炸的一些处理方法

    在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言&#xff0c;在此感激不尽。 权重和梯度的更新公式如下&#xff1a; w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...

    2024/3/20 10:50:27
  3. 力扣贪心算法--第一天

    前言 今天是贪心算法的第一天&#xff0c;算法之路重新开始&#xff01; 内容 之前没了解过贪心算法。 什么是贪心 贪心的本质是选择每一阶段的局部最优&#xff0c;从而达到全局最优。难点就是如何通过局部最优&#xff0c;推出整体最优。 一、455.分发饼干 假设你是一…...

    2024/4/26 23:09:33
  4. 设计模式9--单例模式

    定义 案例一 案例二 优缺点...

    2024/4/27 0:58:53
  5. 416. 分割等和子集问题(动态规划)

    题目 题解 class Solution:def canPartition(self, nums: List[int]) -> bool:# badcaseif not nums:return True# 不能被2整除if sum(nums) % 2 ! 0:return False# 状态定义&#xff1a;dp[i][j]表示当背包容量为j&#xff0c;用前i个物品是否正好可以将背包填满&#xff…...

    2024/4/28 4:04:40
  6. 【Java】ExcelWriter自适应宽度工具类(支持中文)

    工具类 import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet;/*** Excel工具类** author xiaoming* date 2023/11/17 10:40*/ public class ExcelUti…...

    2024/4/28 12:01:04
  7. Spring cloud负载均衡@LoadBalanced LoadBalancerClient

    LoadBalance vs Ribbon 由于Spring cloud2020之后移除了Ribbon&#xff0c;直接使用Spring Cloud LoadBalancer作为客户端负载均衡组件&#xff0c;我们讨论Spring负载均衡以Spring Cloud2020之后版本为主&#xff0c;学习Spring Cloud LoadBalance&#xff0c;暂不讨论Ribbon…...

    2024/4/28 16:34:55
  8. TSINGSEE青犀AI智能分析+视频监控工业园区周界安全防范方案

    一、背景需求分析 在工业产业园、化工园或生产制造园区中&#xff0c;周界防范意义重大&#xff0c;对园区的安全起到重要的作用。常规的安防方式是采用人员巡查&#xff0c;人力投入成本大而且效率低。周界一旦被破坏或入侵&#xff0c;会影响园区人员和资产安全&#xff0c;…...

    2024/4/27 12:24:46
  9. VB.net WebBrowser网页元素抓取分析方法

    在用WebBrowser编程实现网页操作自动化时&#xff0c;常要分析网页Html&#xff0c;例如网页在加载数据时&#xff0c;常会显示“系统处理中&#xff0c;请稍候..”&#xff0c;我们需要在数据加载完成后才能继续下一步操作&#xff0c;如何抓取这个信息的网页html元素变化&…...

    2024/4/28 12:01:03
  10. 【Objective-C】Objective-C汇总

    方法定义 参考&#xff1a;https://www.yiibai.com/objective_c/objective_c_functions.html Objective-C编程语言中方法定义的一般形式如下 - (return_type) method_name:( argumentType1 )argumentName1 joiningArgument2:( argumentType2 )argumentName2 ... joiningArgu…...

    2024/4/28 12:01:03
  11. 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】

    &#x1f468;‍&#x1f4bb;博客主页&#xff1a;花无缺 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! 本文由 花无缺 原创 收录于专栏 【洛谷算法题】 文章目录 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】&#x1f30f;题目描述&#x1f30f;输入格…...

    2024/4/28 12:01:03
  12. 【ES6.0】- 扩展运算符(...)

    【ES6.0】- 扩展运算符... 文章目录 【ES6.0】- 扩展运算符...一、概述二、拷贝数组对象三、合并操作四、参数传递五、数组去重六、字符串转字符数组七、NodeList转数组八、解构变量九、打印日志十、总结 一、概述 **扩展运算符(...)**允许一个表达式在期望多个参数&#xff0…...

    2024/4/28 16:07:14
  13. 摩根看好的前智能硬件头部品牌双11交易数据极度异常!——是模式创新还是饮鸩止渴?

    文 | 螳螂观察 作者 | 李燃 双11狂欢已落下帷幕&#xff0c;各大品牌纷纷晒出优异的成绩单&#xff0c;摩根士丹利投资的智能硬件头部品牌凯迪仕也不例外。然而有爆料称&#xff0c;在自媒体平台发布霸榜各大榜单喜讯的凯迪仕智能锁&#xff0c;多个平台数据都表现出极度异常…...

    2024/4/27 21:08:20
  14. Go语言常用命令详解(二)

    文章目录 前言常用命令go bug示例参数说明 go doc示例参数说明 go env示例 go fix示例 go fmt示例 go generate示例 总结写在最后 前言 接着上一篇继续介绍Go语言的常用命令 常用命令 以下是一些常用的Go命令&#xff0c;这些命令可以帮助您在Go开发中进行编译、测试、运行和…...

    2024/4/28 9:00:42
  15. 用欧拉路径判断图同构推出reverse合法性:1116T4

    http://cplusoj.com/d/senior/p/SS231116D 假设我们要把 a a a 变成 b b b&#xff0c;我们在 a i a_i ai​ 和 a i 1 a_{i1} ai1​ 之间连边&#xff0c; b b b 同理&#xff0c;则 a a a 能变成 b b b 的充要条件是两图 A , B A,B A,B 同构。 必要性显然&#xff0…...

    2024/4/27 18:40:35
  16. 【NGINX--1】基础知识

    1、在 Debian/Ubuntu 上安装 NGINX 在 Debian 或 Ubuntu 机器上安装 NGINX 开源版。 更新已配置源的软件包信息&#xff0c;并安装一些有助于配置官方 NGINX 软件包仓库的软件包&#xff1a; apt-get update apt install -y curl gnupg2 ca-certificates lsb-release debian-…...

    2024/4/28 4:14:21
  17. Hive默认分割符、存储格式与数据压缩

    目录 1、Hive默认分割符2、Hive存储格式3、Hive数据压缩 1、Hive默认分割符 Hive创建表时指定的行受限&#xff08;ROW FORMAT&#xff09;配置标准HQL为&#xff1a; ... ROW FORMAT DELIMITED FIELDS TERMINATED BY \u0001 COLLECTION ITEMS TERMINATED BY , MAP KEYS TERMI…...

    2024/4/27 13:52:15
  18. 【论文阅读】MAG:一种用于航天器遥测数据中有效异常检测的新方法

    文章目录 摘要1 引言2 问题描述3 拟议框架4 所提出方法的细节A.数据预处理B.变量相关分析C.MAG模型D.异常分数 5 实验A.数据集和性能指标B.实验设置与平台C.结果和比较 6 结论 摘要 异常检测是保证航天器稳定性的关键。在航天器运行过程中&#xff0c;传感器和控制器产生大量周…...

    2024/4/27 13:38:13
  19. --max-old-space-size=8192报错

    vue项目运行时&#xff0c;如果经常运行慢&#xff0c;崩溃停止服务&#xff0c;报如下错误 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 因为在 Node 中&#xff0c;通过JavaScript使用内存时只能使用部分内存&#xff08;64位系统&…...

    2024/4/28 12:00:58
  20. 基于深度学习的恶意软件检测

    恶意软件是指恶意软件犯罪者用来感染个人计算机或整个组织的网络的软件。 它利用目标系统漏洞&#xff0c;例如可以被劫持的合法软件&#xff08;例如浏览器或 Web 应用程序插件&#xff09;中的错误。 恶意软件渗透可能会造成灾难性的后果&#xff0c;包括数据被盗、勒索或网…...

    2024/4/28 12:00:58
  21. JS原型对象prototype

    让我简单的为大家介绍一下原型对象prototype吧&#xff01; 使用原型实现方法共享 1.构造函数通过原型分配的函数是所有对象所 共享的。 2.JavaScript 规定&#xff0c;每一个构造函数都有一个 prototype 属性&#xff0c;指向另一个对象&#xff0c;所以我们也称为原型对象…...

    2024/4/27 22:51:49
  22. C++中只能有一个实例的单例类

    C中只能有一个实例的单例类 前面讨论的 President 类很不错&#xff0c;但存在一个缺陷&#xff1a;无法禁止通过实例化多个对象来创建多名总统&#xff1a; President One, Two, Three; 由于复制构造函数是私有的&#xff0c;其中每个对象都是不可复制的&#xff0c;但您的目…...

    2024/4/28 7:31:46
  23. python django 小程序图书借阅源码

    开发工具&#xff1a; PyCharm&#xff0c;mysql5.7&#xff0c;微信开发者工具 技术说明&#xff1a; python django html 小程序 功能介绍&#xff1a; 用户端&#xff1a; 登录注册&#xff08;含授权登录&#xff09; 首页显示搜索图书&#xff0c;轮播图&#xff0…...

    2024/4/28 8:32:05
  24. 电子学会C/C++编程等级考试2022年03月(一级)真题解析

    C/C++等级考试(1~8级)全部真题・点这里 第1题:双精度浮点数的输入输出 输入一个双精度浮点数,保留8位小数,输出这个浮点数。 时间限制:1000 内存限制:65536输入 只有一行,一个双精度浮点数。输出 一行,保留8位小数的浮点数。样例输入 3.1415926535798932样例输出 3.1…...

    2024/4/27 20:28:35
  25. 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...

    解析如下&#xff1a;1、长按电脑电源键直至关机&#xff0c;然后再按一次电源健重启电脑&#xff0c;按F8健进入安全模式2、安全模式下进入Windows系统桌面后&#xff0c;按住“winR”打开运行窗口&#xff0c;输入“services.msc”打开服务设置3、在服务界面&#xff0c;选中…...

    2022/11/19 21:17:18
  26. 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。

    %读入6幅图像&#xff08;每一幅图像的大小是564*564&#xff09; f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...

    2022/11/19 21:17:16
  27. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...

    win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面&#xff0c;在等待界面中我们需要等待操作结束才能关机&#xff0c;虽然这比较麻烦&#xff0c;但是对系统进行配置和升级…...

    2022/11/19 21:17:15
  28. 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...

    有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows&#xff0c;请勿关闭计算机”的提示&#xff0c;要过很久才能进入系统&#xff0c;有的用户甚至几个小时也无法进入&#xff0c;下面就教大家这个问题的解决方法。第一种方法&#xff1a;我们首先在左下角的“开始…...

    2022/11/19 21:17:14
  29. win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...

    置信有很多用户都跟小编一样遇到过这样的问题&#xff0c;电脑时发现开机屏幕显现“正在配置Windows Update&#xff0c;请勿关机”(如下图所示)&#xff0c;而且还需求等大约5分钟才干进入系统。这是怎样回事呢&#xff1f;一切都是正常操作的&#xff0c;为什么开时机呈现“正…...

    2022/11/19 21:17:13
  30. 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...

    Win7系统开机启动时总是出现“配置Windows请勿关机”的提示&#xff0c;没过几秒后电脑自动重启&#xff0c;每次开机都这样无法进入系统&#xff0c;此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一&#xff1a;开机按下F8&#xff0c;在出现的Windows高级启动选…...

    2022/11/19 21:17:12
  31. 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...

    有不少windows10系统用户反映说碰到这样一个情况&#xff0c;就是电脑提示正在准备windows请勿关闭计算机&#xff0c;碰到这样的问题该怎么解决呢&#xff0c;现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法&#xff1a;1、2、依次…...

    2022/11/19 21:17:11
  32. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...

    今天和大家分享一下win7系统重装了Win7旗舰版系统后&#xff0c;每次关机的时候桌面上都会显示一个“配置Windows Update的界面&#xff0c;提示请勿关闭计算机”&#xff0c;每次停留好几分钟才能正常关机&#xff0c;导致什么情况引起的呢&#xff1f;出现配置Windows Update…...

    2022/11/19 21:17:10
  33. 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...

    只能是等着&#xff0c;别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚&#xff0c;只能是考虑备份数据后重装系统了。解决来方案一&#xff1a;管理员运行cmd&#xff1a;net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...

    2022/11/19 21:17:09
  34. 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?

    原标题&#xff1a;电脑提示“配置Windows Update请勿关闭计算机”怎么办&#xff1f;win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢&#xff1f;一般的方…...

    2022/11/19 21:17:08
  35. 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...

    关机提示 windows7 正在配置windows 请勿关闭计算机 &#xff0c;然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;关机提示 windows7 正在配…...

    2022/11/19 21:17:05
  36. 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...

    钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...

    2022/11/19 21:17:05
  37. 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...

    前几天班里有位学生电脑(windows 7系统)出问题了&#xff0c;具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面&#xff0c;长时间没反应&#xff0c;无法进入系统。这个问题原来帮其他同学也解决过&#xff0c;网上搜了不少资料&#x…...

    2022/11/19 21:17:04
  38. 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...

    本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法&#xff0c;并在最后教给你1种保护系统安全的好方法&#xff0c;一起来看看&#xff01;电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中&#xff0c;添加了1个新功能在“磁…...

    2022/11/19 21:17:03
  39. 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...

    许多用户在长期不使用电脑的时候&#xff0c;开启电脑发现电脑显示&#xff1a;配置windows更新失败&#xff0c;正在还原更改&#xff0c;请勿关闭计算机。。.这要怎么办呢&#xff1f;下面小编就带着大家一起看看吧&#xff01;如果能够正常进入系统&#xff0c;建议您暂时移…...

    2022/11/19 21:17:02
  40. 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...

    配置windows update失败 还原更改 请勿关闭计算机&#xff0c;电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;配置windows update失败 还原更改 请勿关闭计算机&#x…...

    2022/11/19 21:17:01
  41. 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...

    不知道大家有没有遇到过这样的一个问题&#xff0c;就是我们的win7系统在关机的时候&#xff0c;总是喜欢显示“准备配置windows&#xff0c;请勿关机”这样的一个页面&#xff0c;没有什么大碍&#xff0c;但是如果一直等着的话就要两个小时甚至更久都关不了机&#xff0c;非常…...

    2022/11/19 21:17:00
  42. 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...

    当电脑出现正在准备配置windows请勿关闭计算机时&#xff0c;一般是您正对windows进行升级&#xff0c;但是这个要是长时间没有反应&#xff0c;我们不能再傻等下去了。可能是电脑出了别的问题了&#xff0c;来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...

    2022/11/19 21:16:59
  43. 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...

    我们使用电脑的过程中有时会遇到这种情况&#xff0c;当我们打开电脑之后&#xff0c;发现一直停留在一个界面&#xff1a;“配置Windows Update失败&#xff0c;还原更改请勿关闭计算机”&#xff0c;等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢&#xff0…...

    2022/11/19 21:16:58
  44. 如何在iPhone上关闭“请勿打扰”

    Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...

    2022/11/19 21:16:57