当前位置:

首页 > 编程开发 > 怎么用Python语言的grpc实现消息传送

怎么用Python语言的grpc实现消息传送

1.grpc开源包的安装#conda$condacreate-ngrpc_envpython=3.9#installgrpc$pipinstallgrpc-ihttps://pypi.doubanio.com/simple$pipinstallgrpc-tools-ihttps://pypi.doubanio.com/simple#有时proto生成py文件不对就是得换换grpc两个包的版本2.grpc的使用之传送消息整体结构,client.pyserver.py和proto目录下的example.pro

本文目录

    1. grpc开源包的安装

    # conda
    $ conda create -n grpc_env python=3.9
     
    # install grpc
    $ pip install grpc -i https://pypi.doubanio.com/simple
    $ pip install grpc-tools -i https://pypi.doubanio.com/simple
     
    # 有时proto生成py文件不对就是得换换grpc两个包的版本

    2. grpc的使用之传送消息

    整体结构,client.py server.py 和proto目录下的example.proto

    怎么用Python语言的grpc实现消息传送

    1)在example.proto定义传送体

    // 声明
    syntax = "proto3";
    package proto;
     
    // service创建
    service HelloService{
      rpc Hello(Request) returns (Response) {}  // 单单传送消息
    }
     
    // 请求参数消息体 1、2是指参数顺序
    message Request {
      string data = 1;
    }
     
    // 返回参数消息体
    message Response {
      int32 ret = 1;    //返回码
      string data = 2;
    }
     
    //python -m grpc_tools.protoc -I ./ --python_out=./ --grpc_python_out=./ ./example.proto

    2) 在虚拟环境里使用命令生成py文件

    $ conda activate grpc_env
    $ f:
    $ cd F:\examples
    $ python -m grpc_tools.protoc -I ./ --python_out=./ --grpc_python_out=./ ./example.proto

    在proto目录下会生成两个py文件,如下图所示:

    怎么用Python语言的grpc实现消息传送

    3) 编辑client.py 和 server.py

    # server.py
    import time
    import grpc
    from concurrent import futures
    from proto import example_pb2_grpc, example_pb2
     
     
    class ServiceBack(example_pb2_grpc.HelloServiceServicer):
        """接口的具体功能实现"""
     
        def Hello(self, request, context):
            """hello"""
            data = request.data
            print(data)
            ret_data = "Response:" + data
            return example_pb2.Response(ret=0, data=ret_data)
     
     
    def server(ip: str, port: int) -> None:
        server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))  # ⼤⼩为10的线程池
        ai_servicer = ServiceBack()
        example_pb2_grpc.add_HelloServiceServicer_to_server(ai_servicer, server)
        server.add_insecure_port(f"{ip}:{port}")  
        server.start()
        try:
            print(f"server is started! ip:{ip} port:{str(port)}")
            while True:
                time.sleep(60 * 60)
        except Exception as es:
            print(es)
            server.stop(0)
     
     
    if __name__ == '__main__':
        server("127.0.0.1", 8000)
    # client.py
    import grpc
    from proto import example_pb2_grpc, example_pb2
     
     
    def client(ip: str, port: int) -> None:
        target = str(ip) + ":" + str(port)
        channel = grpc.insecure_channel(target)  # 连接rpc服务器
        cli = example_pb2_grpc.HelloServiceStub(channel)  # 创建Stub
     
        data = "hello 123"
        request = example_pb2.Request(data=data)
        res = cli.Hello(request)
        print(f"ret:{res.ret}, data:{res.data}")
     
     
    if __name__ == '__main__':
        client("127.0.0.1", 8000)

    3. grpc的使用之数据传输大小配置

    默认情况下,gRPC 将传入消息限制为 4 MB。 传出消息没有限制。

    1)example.proto定义不变

    2)编辑client.py 和 server.py

    # server.py
    import time
    import grpc
    from concurrent import futures
    from proto import example_pb2_grpc, example_pb2
     
     
    class ServiceBack(example_pb2_grpc.HelloServiceServicer):
        """接口的具体功能实现"""
     
        def Hello(self, request, context):
            """hello"""
            data = request.data
            print(data)
            ret_data = "Response:" + data
            return example_pb2.Response(ret=0, data=ret_data)
     
     
    def server(ip: str, port: int) -> None:
        # 数据传输大小配置
        max_message_length = 1024 * 1024 * 1024  # 1G
        options = [('grpc.max_send_message_length', max_message_length),
                   ('grpc.max_receive_message_length', max_message_length),
                   ('grpc.enable_retries', 1),
                   ]
        server = grpc.server(futures.ThreadPoolExecutor(max_workers=10), options=options)  # ⼤⼩为10的线程池
        ai_servicer = ServiceBack()
        example_pb2_grpc.add_HelloServiceServicer_to_server(ai_servicer, server)
        server.add_insecure_port(f"{ip}:{port}")  
        server.start()
        try:
            print(f"server is started! ip:{ip} port:{str(port)}")
            while True:
                time.sleep(60 * 60)
        except Exception as es:
            print(es)
            server.stop(0)
     
     
    if __name__ == '__main__':
        server("127.0.0.1", 8000)
    # client.py
    import grpc
    from proto import example_pb2_grpc, example_pb2
     
     
    def client(ip: str, port: int) -> None:
        # 数据传输大小配置
        max_message_length = 1024 * 1024 * 1024  # 1G
        options = [('grpc.max_send_message_length', max_message_length),
                   ('grpc.max_receive_message_length', max_message_length),
                   ('grpc.enable_retries', 1),
                   ]
        target = str(ip) + ":" + str(port)
        channel = grpc.insecure_channel(target, options=options)  # 连接rpc服务器
        cli = example_pb2_grpc.HelloServiceStub(channel)  # 创建Stub
     
        data = "hello 123" * 1024 * 1024
        request = example_pb2.Request(data=data)
        res = cli.Hello(request)
        print(f"ret:{res.ret}, data:{res.data}")
     
     
    if __name__ == '__main__':
        client("127.0.0.1", 8000)

    4. grpc的使用之超时配置

    1)example.proto定义不变

    2)编辑client.py 和 server.py

    # server.py
    import time
    import grpc
    from concurrent import futures
    from proto import example_pb2_grpc, example_pb2
     
     
    class ServiceBack(example_pb2_grpc.HelloServiceServicer):
        """接口的具体功能实现"""
     
        def Hello(self, request, context):
            """hello"""
            data = request.data
            print(data)
            time.sleep(2)
            ret_data = "Response:" + data
            return example_pb2.Response(ret=0, data=ret_data)
     
     
    def server(ip: str, port: int) -> None:
        # 数据传输大小配置
        max_message_length = 1024 * 1024 * 1024  # 1G
        options = [('grpc.max_send_message_length', max_message_length),
                   ('grpc.max_receive_message_length', max_message_length),
                   ('grpc.enable_retries', 1),
                   ]
        server = grpc.server(futures.ThreadPoolExecutor(max_workers=10), options=options)  # ⼤⼩为10的线程池
        ai_servicer = ServiceBack()
        example_pb2_grpc.add_HelloServiceServicer_to_server(ai_servicer, server)
        server.add_insecure_port(f"{ip}:{port}")  
        server.start()
        try:
            print(f"server is started! ip:{ip} port:{str(port)}")
            while True:
                time.sleep(60 * 60)
        except Exception as es:
            print(es)
            server.stop(0)
     
     
    if __name__ == '__main__':
        server("127.0.0.1", 8000)
    # client.py
    import sys
    import grpc
    from proto import example_pb2_grpc, example_pb2
     
     
    def client(ip: str, port: int) -> None:
        # 数据传输大小配置
        max_message_length = 1024 * 1024 * 1024  # 1G
        options = [('grpc.max_send_message_length', max_message_length),
                   ('grpc.max_receive_message_length', max_message_length),
                   ('grpc.enable_retries', 1),
                   ]
        target = str(ip) + ":" + str(port)
        channel = grpc.insecure_channel(target, options=options)  # 连接rpc服务器
        cli = example_pb2_grpc.HelloServiceStub(channel)  # 创建Stub
        try:
            data = "hello 123"
            request = example_pb2.Request(data=data)
            res = cli.Hello(request, timeout=1)  # timeout 单位:秒
            print(f"ret:{res.ret}, data:{res.data}")
        except grpc.RpcError as rpc_error:
            print("grpc.RpcError", rpc_error.details())
        except Exception as es:
            print(es)
        finally:
            sys.exit(-1)
     
     
    if __name__ == '__main__':
        client("127.0.0.1", 8000)

    运行结果:

    grpc.RpcError Deadline Exceeded

    5. grpc之大文件之流stream传输

    1)在example.proto重新定义传送体

    // 声明
    syntax = "proto3";
    package proto;
     
    // service创建
    service HelloService{
      rpc Hello(Request) returns (Response) {}  // 单单传送消息
      rpc ClientTOServer(stream UpFileRequest) returns (Response) {}  // 流式上传文件
      rpc ServerTOClient(Request) returns (stream UpFileRequest) {}  // 流式下载文件
    }
     
    // 请求参数消息体 1、2是指参数顺序
    message Request {
      string data = 1;
    }
     
    // 返回参数消息体
    message Response {
      int32 ret = 1;    //返回码
      string data = 2;
    }
     
    message UpFileRequest {
      string filename = 1;
      int64 sendsize = 2;
      int64 totalsize = 3;
      bytes data = 4;
    }
     
     
    //python -m grpc_tools.protoc -I ./ --python_out=./ --grpc_python_out=./ ./example.proto

    2)在虚拟环境里使用命令生成py文件,参考2. 2)

    3)编辑client.py 和 server.py

    # server.py
    import os
    import time
    import grpc
    from concurrent import futures
    from proto import example_pb2_grpc, example_pb2
     
     
    class ServiceBack(example_pb2_grpc.HelloServiceServicer):
        """接口的具体功能实现"""
     
        def Hello(self, request, context):
            """hello"""
            data = request.data
            print(data)
            time.sleep(2)
            ret_data = "Response:" + data
            return example_pb2.Response(ret=0, data=ret_data)
     
        def ClientTOServer(self, request_iterator, context):
            """上传文件"""
            data = bytearray()
            for UpFileRequest in request_iterator:
                file_name = UpFileRequest.filename
                file_size = UpFileRequest.totalsize
                file_data = UpFileRequest.data
                print(f"文件名称:{file_name}, 文件总长度:{file_size}")
                data.extend(file_data)  # 拼接两个bytes
                print(f"已接收长度:{len(data)}")
            if len(data) == file_size:
                with open("242_copy.mp3", "wb") as fw:
                    fw.write(data)
                print(f"{file_name=} 下载完成")
                (ret, res) = (0, file_name)
            else:
                print(f"{file_name=} 下载失败")
                (ret, res) = (-1, file_name)
            return example_pb2.Response(ret=ret, data=res)
     
        def ServerTOClient(self, request, context):
            """下载文件"""
            fp = request.data
            print(f"下载文件:{fp=}")
            # 获取文件名和文件大小
            file_name = os.path.basename(fp)
            file_size = os.path.getsize(fp)  # 获取文件大小
            # 发送文件内容
            part_size = 1024 * 1024  # 每次读取1MB数据
            count = 1
     
            with open(fp, "rb") as fr:
                while True:
                    try:
                        if count == 1:
                            count += 1
                            yield example_pb2.UpFileRequest(filename=file_name, totalsize=file_size, sendsize=0, data=b"")
                        else:
                            context = fr.read(part_size)
                            if context:
                                yield example_pb2.UpFileRequest(filename=file_name, totalsize=file_size,
                                                                sendsize=len(context),
                                                                data=context)
                            else:
                                print(f"发送完毕")
                                return 0
                    except Exception as es:
                        print(es)
     
     
    def server(ip: str, port: int) -> None:
        # 数据传输大小配置
        max_message_length = 1024 * 1024 * 1024  # 1G
        options = [('grpc.max_send_message_length', max_message_length),
                   ('grpc.max_receive_message_length', max_message_length),
                   ('grpc.enable_retries', 1),
                   ]
        server = grpc.server(futures.ThreadPoolExecutor(max_workers=10), options=options)  # ⼤⼩为10的线程池
        ai_servicer = ServiceBack()
        example_pb2_grpc.add_HelloServiceServicer_to_server(ai_servicer, server)
        server.add_insecure_port(f"{ip}:{port}")  
        server.start()
        try:
            print(f"server is started! ip:{ip} port:{str(port)}")
            while True:
                time.sleep(60 * 60)
        except Exception as es:
            print(es)
            server.stop(0)
     
     
    if __name__ == '__main__':
        server("127.0.0.1", 8000)
    # client.py
    import os
    import sys
    import grpc
    from proto import example_pb2_grpc, example_pb2
     
     
    def send_stream_data(fp: str):
        """迭代器发送大文件"""
        # 获取文件名和文件大小
        file_name = os.path.basename(fp)
        file_size = os.path.getsize(fp)  # 获取文件大小
        # 发送文件内容
        part_size = 1024 * 1024  # 每次读取1MB数据
        count = 1
     
        with open(fp, "rb") as fr:
            while True:
                try:
                    if count == 1:
                        count += 1
                        yield example_pb2.UpFileRequest(filename=file_name, totalsize=file_size, sendsize=0, data=b"")
                    else:
                        context = fr.read(part_size)
                        if context:
                            yield example_pb2.UpFileRequest(filename=file_name, totalsize=file_size, sendsize=len(context),
                                                            data=context)
                        else:
                            print(f"发送完毕")
                            return 0
                except Exception as es:
                    print(es)
     
     
    def client(ip: str, port: int) -> None:
        # 数据传输大小配置
        max_message_length = 1024 * 1024 * 1024  # 1G
        options = [('grpc.max_send_message_length', max_message_length),
                   ('grpc.max_receive_message_length', max_message_length),
                   ('grpc.enable_retries', 1),
                   ]
        target = str(ip) + ":" + str(port)
        channel = grpc.insecure_channel(target, options=options)  # 连接rpc服务器
        cli = example_pb2_grpc.HelloServiceStub(channel)  # 创建Stub
        try:
            data = "hello 123"
            request = example_pb2.Request(data=data)
            res = cli.Hello(request, timeout=1)  # timeout 单位:秒
            print(f"ret:{res.ret}, data:{res.data}")
        except grpc.RpcError as rpc_error:
            print("grpc.RpcError", rpc_error.details())
        except Exception as es:
            print(es)
        finally:
            sys.exit(-1)
     
     
    def client_to_server(ip: str, port: int, fp: str):
        """
        流式上传数据。
        """
        # 数据传输大小配置
        max_message_length = 1024 * 1024 * 1024  # 1G
        options = [('grpc.max_send_message_length', max_message_length),
                   ('grpc.max_receive_message_length', max_message_length),
                   ('grpc.enable_retries', 1),
                   ]
        target = str(ip) + ":" + str(port)
        channel = grpc.insecure_channel(target, options=options)  # 连接rpc服务器
        cli = example_pb2_grpc.HelloServiceStub(channel)  # 创建Stub
        try:
            request = send_stream_data(fp=fp)
            res = cli.ClientTOServer(request, timeout=600)  # timeout 单位:秒
            print(f"ret:{res.ret}, data:{res.data}")
        except grpc.RpcError as rpc_error:
            print("grpc.RpcError", rpc_error.details())
        except Exception as es:
            print(es)
        finally:
            sys.exit(-1)
     
     
    def server_to_client(ip: str, port: int, fp: str):
        """
        流式上传数据。
        """
        # 数据传输大小配置
        max_message_length = 1024 * 1024 * 1024  # 1G
        options = [('grpc.max_send_message_length', max_message_length),
                   ('grpc.max_receive_message_length', max_message_length),
                   ('grpc.enable_retries', 1),
                   ]
        target = str(ip) + ":" + str(port)
        channel = grpc.insecure_channel(target, options=options)  # 连接rpc服务器
        cli = example_pb2_grpc.HelloServiceStub(channel)  # 创建Stub
        try:
            data = bytearray()
            request = example_pb2.Request(data=fp)
            filename = ""
            for res in cli.ServerTOClient(request, timeout=300):
                filename = res.filename
                total_size = res.totalsize
                data += res.data
            if total_size == len(data):
                with open("242_1.mp3", "wb") as fw:
                    fw.write(data)
                print(f"{filename=} : {total_size=} 下载完成!")
            else:
                print(f"{filename=} 下载失败!")
        except grpc.RpcError as rpc_error:
            print("grpc.RpcError", rpc_error.details())
        except Exception as es:
            print(es)
        finally:
            sys.exit(-1)
     
     
    if __name__ == '__main__':
        # client("127.0.0.1", 8000)
        # client_to_server("127.0.0.1", 8000, "242.mp3")
        server_to_client("127.0.0.1", 8000, "242.mp3")

    6. grpc之大文件之流async异步传输

    # server.py
    import os
    import time
    import grpc
    from concurrent import futures
    from proto import example_pb2_grpc, example_pb2
    import asyncio
     
     
    class ServiceBack(example_pb2_grpc.HelloServiceServicer):
        """接口的具体功能实现"""
     
        def Hello(self, request, context):
            """hello"""
            data = request.data
            print(data)
            time.sleep(2)
            ret_data = "Response:" + data
            return example_pb2.Response(ret=0, data=ret_data)
     
        def ClientTOServer(self, request_iterator, context):
            """上传文件"""
            data = bytearray()
            for UpFileRequest in request_iterator:
                file_name = UpFileRequest.filename
                file_size = UpFileRequest.totalsize
                file_data = UpFileRequest.data
                print(f"文件名称:{file_name}, 文件总长度:{file_size}")
                data.extend(file_data)  # 拼接两个bytes
                print(f"已接收长度:{len(data)}")
            if len(data) == file_size:
                with open("242_copy.mp3", "wb") as fw:
                    fw.write(data)
                print(f"{file_name=} 下载完成")
                (ret, res) = (0, file_name)
            else:
                print(f"{file_name=} 下载失败")
                (ret, res) = (-1, file_name)
            return example_pb2.Response(ret=ret, data=res)
     
        def ServerTOClient(self, request, context):
            """下载文件"""
            fp = request.data
            print(f"下载文件:{fp=}")
            # 获取文件名和文件大小
            file_name = os.path.basename(fp)
            file_size = os.path.getsize(fp)  # 获取文件大小
            # 发送文件内容
            part_size = 1024 * 1024  # 每次读取1MB数据
            count = 1
     
            with open(fp, "rb") as fr:
                while True:
                    try:
                        if count == 1:
                            count += 1
                            yield example_pb2.UpFileRequest(filename=file_name, totalsize=file_size, sendsize=0, data=b"")
                        else:
                            context = fr.read(part_size)
                            if context:
                                yield example_pb2.UpFileRequest(filename=file_name, totalsize=file_size,
                                                                sendsize=len(context),
                                                                data=context)
                            else:
                                print(f"发送完毕")
                                return 0
                    except Exception as es:
                        print(es)
     
     
    async def server(ip: str, port: int) -> None:
        # 数据传输大小配置
        max_message_length = 1024 * 1024 * 1024  # 1G
        options = [('grpc.max_send_message_length', max_message_length),
                   ('grpc.max_receive_message_length', max_message_length),
                   ('grpc.enable_retries', 1),
                   ]
        server = grpc.aio.server(futures.ThreadPoolExecutor(max_workers=10), options=options)  # ⼤⼩为10的线程池
        ai_servicer = ServiceBack()
        example_pb2_grpc.add_HelloServiceServicer_to_server(ai_servicer, server)
        server.add_insecure_port(f"{ip}:{port}")
        await server.start()
        try:
            print(f"server is started! ip:{ip} port:{str(port)}")
            await server.wait_for_termination()
        except Exception as es:
            print(es)
            await server.stop(None)
     
     
    if __name__ == '__main__':
        loop = asyncio.get_event_loop()
        loop.run_until_complete(asyncio.wait([server("127.0.0.1", 8000)]))
        loop.close()
    # client.py
    import os
    import sys
    import grpc
    from proto import example_pb2_grpc, example_pb2
    import asyncio
     
     
    def send_stream_data(fp: str):
        """迭代器发送大文件"""
        # 获取文件名和文件大小
        file_name = os.path.basename(fp)
        file_size = os.path.getsize(fp)  # 获取文件大小
        # 发送文件内容
        part_size = 1024 * 1024  # 每次读取1MB数据
        count = 1
     
        with open(fp, "rb") as fr:
            while True:
                try:
                    if count == 1:
                        count += 1
                        yield example_pb2.UpFileRequest(filename=file_name, totalsize=file_size, sendsize=0, data=b"")
                    else:
                        context = fr.read(part_size)
                        if context:
                            yield example_pb2.UpFileRequest(filename=file_name, totalsize=file_size, sendsize=len(context),
                                                            data=context)
                        else:
                            print(f"发送完毕")
                            return 0
                except Exception as es:
                    print(es)
     
     
    async def client(ip: str, port: int) -> None:
        # 数据传输大小配置
        max_message_length = 1024 * 1024 * 1024  # 1G
        options = [('grpc.max_send_message_length', max_message_length),
                   ('grpc.max_receive_message_length', max_message_length),
                   ('grpc.enable_retries', 1),
                   ]
        target = str(ip) + ":" + str(port)
        async with grpc.aio.insecure_channel(target, options=options) as channel:  # 连接rpc服务器
            cli = example_pb2_grpc.HelloServiceStub(channel)  # 创建Stub
            try:
                data = "hello 123"
                request = example_pb2.Request(data=data)
                res = await cli.Hello(request, timeout=3)  # timeout 单位:秒
                print(f"ret:{res.ret}, data:{res.data}")
            except grpc.RpcError as rpc_error:
                print("grpc.RpcError", rpc_error.details())
            except Exception as es:
                print(es)
            finally:
                sys.exit(-1)
     
     
    async def client_to_server(ip: str, port: int, fp: str):
        """
        流式上传数据。
        """
        # 数据传输大小配置
        max_message_length = 1024 * 1024 * 1024  # 1G
        options = [('grpc.max_send_message_length', max_message_length),
                   ('grpc.max_receive_message_length', max_message_length),
                   ('grpc.enable_retries', 1),
                   ]
        target = str(ip) + ":" + str(port)
        async with grpc.aio.insecure_channel(target, options=options) as channel:  # 连接rpc服务器
            cli = example_pb2_grpc.HelloServiceStub(channel)  # 创建Stub
            try:
                request = send_stream_data(fp=fp)
                res = await cli.ClientTOServer(request, timeout=600)  # timeout 单位:秒
                print(f"ret:{res.ret}, data:{res.data}")
            except grpc.RpcError as rpc_error:
                print("grpc.RpcError", rpc_error.details())
            except Exception as es:
                print(es)
            finally:
                sys.exit(-1)
     
     
    def server_to_client(ip: str, port: int, fp: str):
        """
        流式上传数据。
        """
        # 数据传输大小配置
        max_message_length = 1024 * 1024 * 1024  # 1G
        options = [('grpc.max_send_message_length', max_message_length),
                   ('grpc.max_receive_message_length', max_message_length),
                   ('grpc.enable_retries', 1),
                   ]
        target = str(ip) + ":" + str(port)
        channel = grpc.insecure_channel(target, options=options)  # 连接rpc服务器
        cli = example_pb2_grpc.HelloServiceStub(channel)  # 创建Stub
        try:
            data = bytearray()
            request = example_pb2.Request(data=fp)
            filename = ""
            for res in cli.ServerTOClient(request, timeout=300):
                filename = res.filename
                total_size = res.totalsize
                data += res.data
            if total_size == len(data):
                with open("242_1.mp3", "wb") as fw:
                    fw.write(data)
                print(f"{filename=} : {total_size=} 下载完成!")
            else:
                print(f"{filename=} 下载失败!")
        except grpc.RpcError as rpc_error:
            print("grpc.RpcError", rpc_error.details())
        except Exception as es:
            print(es)
        finally:
            sys.exit(-1)
     
     
    if __name__ == '__main__':
        # asyncio.run(client("127.0.0.1", 8000))
        asyncio.run(client_to_server("127.0.0.1", 8000, "242.mp3"))
        # server_to_client("127.0.0.1", 8000, "242.mp3")
    本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系bd@zhengruan.com
    作者最新文章
    编程开发 Python
    相关文章 更多
    python删除一个列表里的重复元素的方法与代码示例
    python删除一个列表里的重复元素的方法与代码示例

    学习如何使用Python高效删除列表中的重复元素。本文提供5种常见方法的代码示例,涵盖保持顺序与不保持顺序的场景,适合初学者和进阶开发者参考。

    Python写接口的步骤及完整代码示例
    Python写接口的步骤及完整代码示例

    详细讲解使用Python编写Web接口的核心步骤与完整代码示例,涵盖环境准备、路由定义、数据校验、服务启动及调试测试方法。

    codex怎么读取word文档及docx文件操作教程
    codex怎么读取word文档及docx文件操作教程

    介绍如何利用编程工具读取和解析Word文档(docx格式),涵盖基础文本提取代码示例、结构化数据处理逻辑,以及处理复杂排版时的技术局限与替代方案。

    怎么在Python中调用C语言代码提升性能
    怎么在Python中调用C语言代码提升性能

    详细讲解在Python中调用C语言代码提升性能的完整实践指南,包含原理分析、编译步骤、ctypes与CFFI具体实现、性能对比及常见陷阱。

    Python与C语言的性能差异及底层原理
    Python与C语言的性能差异及底层原理

    深入解析Python与C语言在执行效率上的数量级差异,从编译机制、变量内存布局、动态类型推断到GIL锁,系统阐明底层核心原理。

    Python和C语言哪个更适合编程入门
    Python和C语言哪个更适合编程入门

    客观对比Python与C语言在心智负担、底层机制与学习反馈上的核心差异,提供清晰有据的选择标准与切实的入门学习路径。

    selenium上传文件教程本地文件路径设置方法
    selenium上传文件教程本地文件路径设置方法

    深入解析Selenium处理文件上传的技术细节,涵盖标准HTML控件的路径直接注入法与非标准控件的系统级模拟方案,提供Windows与Linux环境下的路径设置最佳实践及常见异常排查。

    大数据开发语言选型:Java对比Scala与Python的优缺点及适用场景
    大数据开发语言选型:Java对比Scala与Python的优缺点及适用场景

    针对大数据工程场景,系统对比Java、Scala与Python在执行性能、生态结合、开发效率和维护成本上的核心差异,给出清晰的架构选型依据与落地方案。

    langgraph python guide中文入门教程详解
    langgraph python guide中文入门教程详解

    本篇LangGraph Python中文入门教程详解,系统梳理StateGraph状态机定义、节点编写、边与条件路由、检查点持久化(MemorySaver)等核心机制,提供从环境安装到完整循环智能体构建的代码示例与实操指导。

    Windows 安装 Python:从官方入口到虚拟环境的可复现实践
    Windows 安装 Python:从官方入口到虚拟环境的可复现实践

    面向后端开发者,基于 Python 官方文档说明如何在 Windows 上安装 Python、创建 venv 虚拟环境及使用 pip 管理依赖。包含可复制命令、验证方法及工具选择边界,避免常见配置误区。

    查看更多
    精品专题 更多
    装机必备
    装机必备

    正软商城装机必备专区,精选办公、浏览器、安全防护、影音播放、压缩解压、设计创作和系统工具等电脑常用正版软件,帮助用户快速完成新电脑软件配置。

    Windows
    Windows

    正软商城Windows软件专区,汇集适用于Windows电脑的办公、设计、安全防护、影音播放、开发工具和系统优化软件,提供软件介绍、系统要求、正版授权及购买下载服务。

    PDF教程
    PDF教程

    正软商城PDF教程频道提供PDF编辑、转换、合并、拆分、压缩及格式处理方法,同时介绍常用PDF软件和工具的使用技巧。

    Mac软件 更多
    讯飞智作 网页版
    讯飞智作 网页版
    Windows/ macOS/ Linux

    讯飞智作是一款基于语音合成技术、虚拟人驱动技术与数字人形象声音构建能力的 AI 数字人音视频创作平台。

    火山引擎 网页版
    火山引擎 网页版
    Windows/ macOS/ Linux

    火山引擎是字节跳动旗下企业级云与AI服务平台。聚焦大模型核心能力,依托字节自研豆包多模态大模型,凭借火山方舟一站式平台,提供模型精调、推理部署、智能应用搭建等全链路服务,结合高性能AI算力,助力各行业快速落地大模型数字化与智能化应用。

    Aperty macOS版
    Aperty macOS版
    macOS

    Aperty 是 Skylum 推出的 AI 人像修图软件,支持自然肤质修饰、瑕疵处理、面部与身体调整、预设及批量同步。

    WINDOWS 更多
    讯飞智作 网页版
    讯飞智作 网页版
    Windows/ macOS/ Linux

    讯飞智作是一款基于语音合成技术、虚拟人驱动技术与数字人形象声音构建能力的 AI 数字人音视频创作平台。

    火山引擎 网页版
    火山引擎 网页版
    Windows/ macOS/ Linux

    火山引擎是字节跳动旗下企业级云与AI服务平台。聚焦大模型核心能力,依托字节自研豆包多模态大模型,凭借火山方舟一站式平台,提供模型精调、推理部署、智能应用搭建等全链路服务,结合高性能AI算力,助力各行业快速落地大模型数字化与智能化应用。

    PixTV 网页版
    PixTV 网页版
    Windows

    PixTV 是一款在浏览器中使用的 AI 视觉内容创作平台,提供图片、视频、音频、文字生成、AI 分镜、局部重绘、提示词反推和无限画布等工具,适合短剧、漫剧、广告及社交媒体内容制作。