用举例来学习Python中的并行性、并发性和异步性

2023-12-19

Parallelism, Concurrency, and AsyncIO in Python - by example

用举例来学习Python中的并行性、并发性和异步性

一篇中文译文,来自:( Parallelism, Concurrency, and AsyncIO in Python - by example | TestDriven.io ) Posted by Amal Shaji

This tutorial looks at how to speed up CPU-bound and IO-bound operations with multiprocessing, threading, and AsyncIO. 本教程介绍如何通过多进程、线程和 AsyncIO 来加速 CPU 密集型和 IO 密集型操作。

Concurrency vs Parallelism 并发与并行

Concurrency and parallelism are similar terms, but they are not the same thing. 并发和并行是相似的术语,但它们不是同一件事。

Concurrency is the ability to run multiple tasks on the CPU at the same time. Tasks can start, run, and complete in overlapping time periods. In the case of a single CPU, multiple tasks are run with the help of context switching , where the state of a process is stored so that it can be called and executed later. 并发性是指在 CPU 上同时运行多个任务的能力。任务可以在重叠的时间段内启动、运行和完成。在单CPU的情况下,多个任务在 上下文切换 的帮助下运行,其中(上下文中)存储了进程的状态,以便稍后调用和执行。

Parallelism, meanwhile, is the ability to run multiple tasks at the same time across multiple CPU cores. 与此同时,并行(Parallelism)是指在多个 CPU 核心上同时运行多个任务(multiple tasks)的能力。

Though they can increase the speed of your application, concurrency and parallelism should not be used everywhere. The use case depends on whether the task is CPU-bound or IO-bound. 尽管它们可以提高应用程序的速度,但并发(concurrency)和并行(Parallelism)不应该在所有的地方使用。是否使用取决于任务是 CPU 密集型(CPU-bound)还是 IO 密集型(IO-bound)。

Tasks that are limited by the CPU are CPU-bound. For example, mathematical computations are CPU-bound since computational power increases as the number of computer processors increases. Parallelism is for CPU-bound tasks. 受 CPU 限制的任务是 CPU 密集型的。例如,数学计算受 CPU 限制,因为计算能力随着计算机处理器数量的增加而增加。并行(Parallelism)适用于 CPU 密集型任务。

In theory, If a task is divided into n-subtasks, each of these n-tasks can run in parallel to effectively reduce the time to 1/n of the original non-parallel task. Concurrency is preferred for IO-bound tasks, as you can do something else while the IO resources are being fetched. 理论上,如果一个任务被划分为n个子任务,那么这n个子任务中的每一个都可以并行运行,从而有效地将运行时间减少到原来非并行运行时的1/n。对于 IO 密集型(IO-bound)任务来说,并发(Concurrency)是首选,因为您可以在 IO 资源正在被获取的同时去做其他操作。

The best example of CPU-bound tasks is in data science. Data scientists deal with huge chunks of data. For data preprocessing, they can split the data into multiple batches and run them in parallel, effectively decreasing the total time to process.Increasing the number of cores results in faster processing. CPU 密集型(CPU-bound)任务的最佳示例是数据科学。数据科学家处理大量数据。对于数据预处理,他们可以将数据分成多个批次并行(parallel)运行,从而有效减少总处理时间。增加核心数量可以加快处理速度。

Web scraping is IO-bound. Because the task has little effect on the CPU since most of the time is spent on reading from and writing to the network. Other common IO-bound tasks include database calls and reading and writing files to disk.Web applications, like Django and Flask, are IO-bound applications. Web 抓取是 IO 密集型(IO-bound)。因为该任务对 CPU 的影响很小,因为大部分时间都花在网络读写上。其他常见的 IO 密集型任务包括数据库调用以及向磁盘读取和写入文件。Web 应用程序(例如 Django 和 Flask)是 IO 密集型应用程序。

If you’re interested in learning more about the differences between threads, multiprocessing, and async in Python, check out the Speeding Up Python with Concurrency, Parallelism, and asyncio article. 如果您有兴趣了解有关 Python 中线程、多处理和异步之间差异的更多信息,请查看通过 并发、并行和异步加速 Python 文章

Scenario 设想

With that, let’s take a look at how to speed up the following tasks: 接下来,让我们看看如何加快以下任务的速度:

# tasks.py

import os
from multiprocessing import current_process
from threading import current_thread

import requests

def make_request(num):
    # io-bound

    pid = os.getpid()
    thread_name = current_thread().name
    process_name = current_process().name
    print(f"{pid} - {process_name} - {thread_name}")

    requests.get("https://httpbin.org/ip")

async def make_request_async(num, client):
    # io-bound

    pid = os.getpid()
    thread_name = current_thread().name
    process_name = current_process().name
    print(f"{pid} - {process_name} - {thread_name}")

    await client.get("https://httpbin.org/ip")

def get_prime_numbers(num):
    # cpu-bound

    pid = os.getpid()
    thread_name = current_thread().name
    process_name = current_process().name
    print(f"{pid} - {process_name} - {thread_name}")

    numbers = []

    prime = [True for i in range(num + 1)]
    p = 2

    while p * p <= num:
        if prime[p]:
            for i in range(p * 2, num + 1, p):
                prime[i] = False
        p += 1

    prime[0] = False
    prime[1] = False

    for p in range(num + 1):
        if prime[p]:
            numbers.append(p)

    return numbers

All of the code examples in this tutorial can be found in the parallel-concurrent-examples-python repo.z 本教程中的所有代码示例都可以在 parallel-concurrent-examples-python 存储库中找到。

Notes: 笔记(上面代码中的函数说明):

  • make_request makes an HTTP request to httpbin.org/ip X number of times.
  • make_request httpbin.org/ip 发出 HTTP 请求 X 次。
  • make_request_async makes the same HTTP request asynchronously with HTTPX .
  • make_request_async 使用 HTTPX 异步(asynchronously )发出相同的 HTTP 请求。
  • get_prime_numbers calculates the prime numbers, via the Sieve of Eratosthenes method, from two to the provided limit.
  • get_prime_numbers 通过埃拉托斯特尼筛法计算从 2 到 指定数值 间的素数。

We’ll be using the following libraries from the standard library to speed up the above tasks: 我们将使用标准库中的以下库来加速上述任务:

  • threading for running tasks concurrently

  • threading 线程 用于并发运行任务的

  • multiprocessing for running tasks in parallel

  • multiprocessing 多进程 并行运行任务的

  • concurrent.futures for running tasks concurrently and in parallel from a single interface

  • concurrent.futures 异步并发 用于并发运行任务,以及从单个接口并行

    (注:concurrent.futures是重要的 异步编程 库。内部实现机制非常复杂,简单来说就是开辟一个固定大小为n的进程池/线程池。进程池中最多执行n个进程/线程,当任务完成后,从任务队列中取新任务。若池满,则排队等待。)

  • asyncio for running tasks concurrency with coroutines managed by the Python interpreter

  • asyncio 异步IO 用于使用 Python 解释器管理的 协程 coroutines 并发运行任务

Library 图书馆 Class/Method 类/方法 Processing Type 加工类型
threading 线程 Thread 线程 concurrent 并发
concurrent.futures 异步并发 ThreadPoolExecutor 线程池执行器 concurrent 并发
asyncio 异步IO gather 收集 concurrent (via coroutines) 并发(通过协程)
multiprocessing 多进程 Pool 池 parallel 并行
concurrent.futures 异步并发 ProcessPoolExecutor 进程池执行器 parallel 并行

IO-bound Operation IO 绑定操作

Again, IO-bound tasks spend more time on IO than on the CPU. 同样,IO 密集型任务在 IO 上花费的时间比在 CPU 上花费的时间更多。

Since web scraping is IO bound, we should use threading to speed up the processing as the retrieving of the HTML (IO) is slower than parsing it (CPU). 由于网页抓取受 IO 限制,因此我们应该使用线程(threading )来加快处理速度,因为 HTML 的检索 (IO) 比解析它 (CPU) 慢。

Scenario: How to speed up a Python-based web scraping and crawling script? 场景:如何加速基于Python的网页抓取和爬行脚本?

Sync Example 同步示例

Let’s start with a benchmark. 让我们从一个基准测试程序(benchmark)开始。

# io-bound_sync.py

import time

from tasks import make_request

def main():
    for num in range(1, 101):
        make_request(num)

if __name__ == "__main__":
    start_time = time.perf_counter()

    main()

    end_time = time.perf_counter()
    print(f"Elapsed run time: {end_time - start_time} seconds.")

Here, we made 100 HTTP requests using the make_request function. Since requests happen synchronously, each task is executed sequentially. 在这里,我们使用 make_request 函数发出 100 个 HTTP 请求。由于请求是同步(synchronously)发生的,因此每个任务都是按顺序执行的。

Elapsed run time: 15.710984757 seconds.

So, that’s roughly 0.16 seconds per request. 因此,每个请求大约需要 0.16 秒。

Threading Example 线程示例

# io-bound_concurrent_1.py

import threading
import time

from tasks import make_request

def main():
    tasks = []

    for num in range(1, 101):
        tasks.append(threading.Thread(target=make_request, args=(num,)))
        tasks[-1].start()

    for task in tasks:
        task.join()

if __name__ == "__main__":
    start_time = time.perf_counter()

    main()

    end_time = time.perf_counter()
    print(f"Elapsed run time: {end_time - start_time} seconds.")

Here, the same make_request function is called 100 times. This time the threading library is used to create a thread for each request. 此处,相同的 make_request 函数被调用 100 次。这次使用 threading 库为每个请求创建一个线程。

Elapsed run time: 1.020112515 seconds.

The total time decreases from ~16s to ~1s. 总时间从约 16 秒减少到约 1 秒。

Since we’re using separate threads for each request, you might be wondering why the whole thing didn’t take ~0.16s to finish. This extra time is the overhead for managing threads. The Global Interpreter Lock (GIL) in Python makes sure that only one thread uses the Python bytecode at a time. 由于我们对每个请求使用单独的线程,因此您可能想知道为什么整个事情不是花费大约 0.16 秒(16 秒/100个线程=0.16 秒)完成。这个额外的耗费时间就是管理线程的开销。 Python 中的 全局解释器锁 (GIL) 确保一次只有一个线程使用 Python 字节码。

concurrent.futures Example concurrent.futures示例

# io-bound_concurrent_2.py

import time
from concurrent.futures import ThreadPoolExecutor, wait

from tasks import make_request

def main():
    futures = []

    with ThreadPoolExecutor() as executor:
        for num in range(1, 101):
            futures.append(executor.submit(make_request, num))

    wait(futures)

if __name__ == "__main__":
    start_time = time.perf_counter()

    main()

    end_time = time.perf_counter()
    print(f"Elapsed run time: {end_time - start_time} seconds.")

Here we used concurrent.futures.ThreadPoolExecutor to achieve multithreading. After all the futures/promises are created, we used wait to wait for all of them to complete. 这里我们使用 concurrent.futures.ThreadPoolExecutor 来实现多线程。创建所有 futures/promise 后,我们使用 wait 等待它们全部完成。

Elapsed run time: 1.340592231 seconds

concurrent.futures.ThreadPoolExecutor is actually an abstraction around the multithreading library, which makes it easier to use. In the previous example, we assigned each request to a thread and in total 100 threads were used. But ThreadPoolExecutor defaults the number of worker threads to min(32, os.cpu_count() + 4) . ThreadPoolExecutor exists to ease the process of achieving multithreading. If you want more control over multithreading, use the multithreading library instead. concurrent.futures.ThreadPoolExecutor 实际上是对 multithreading 库的抽象,这使得它更易于使用。在前面的示例中,我们将每个请求分配给一个线程,总共使用了 100 个线程。但 ThreadPoolExecutor 默认工作线程数为 min(32, os.cpu_count() + 4) 。 ThreadPoolExecutor 的存在是为了简化实现多线程的过程。如果您想要对多线程进行更多控制,请改用 multithreading 库。

AsyncIO Example 异步IO示例

# io-bound_concurrent_3.py

import asyncio
import time

import httpx

from tasks import make_request_async

async def main():
    async with httpx.AsyncClient() as client:
        return await asyncio.gather(
            *[make_request_async(num, client) for num in range(1, 101)]
        )

if __name__ == "__main__":
    start_time = time.perf_counter()

    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

    end_time = time.perf_counter()
    elapsed_time = end_time - start_time
    print(f"Elapsed run time: {elapsed_time} seconds")

httpx is used here since requests does not support async operations. 此处使用 httpx ,因为 requests 不支持异步操作。

Here, we used asyncio to achieve concurrency. 这里,我们使用 asyncio 来实现并发。

Elapsed run time: 0.553961068 seconds

asyncio is faster than the other methods, because threading makes use of OS (Operating System) threads. So the threads are managed by the OS, where thread switching is preempted by the OS. asyncio uses coroutines, which are defined by the Python interpreter. With coroutines, the program decides when to switch tasks in an optimal way. This is handled by the even_loop in asyncio. asyncio 比其他方法更快,因为 threading 使用 OS(操作系统)线程。因此线程由操作系统管理,其中线程切换由操作系统抢占。 asyncio 使用由 Python 解释器定义的协程。通过协程,程序可以决定何时以最佳方式切换任务。这是由 asyncio 中的 even_loop 处理的。

CPU-bound Operation CPU 密集型操作

Scenario: How to speed up a simple data processing script? 场景:如何加速一个简单的数据处理脚本?

Sync Example 同步示例

Again, let’s start with a benchmark. 再次,让我们从基准测试程序开始。

# cpu-bound_sync.py

import time

from tasks import get_prime_numbers

def main():
    for num in range(1000, 16000):
        get_prime_numbers(num)

if __name__ == "__main__":
    start_time = time.perf_counter()

    main()

    end_time = time.perf_counter()
    print(f"Elapsed run time: {end_time - start_time} seconds.")

Here, we executed the get_prime_numbers function for numbers from 1000 to 16000. 在这里,我们对 1000 到 16000 之间的数字执行 get_prime_numbers 函数。

Elapsed run time: 17.863046316 seconds.

Multiprocessing Example 多进程示例

# cpu-bound_parallel_1.py

import time
from multiprocessing import Pool, cpu_count

from tasks import get_prime_numbers

def main():
    with Pool(cpu_count() - 1) as p:
        p.starmap(get_prime_numbers, zip(range(1000, 16000)))
        p.close()
        p.join()

if __name__ == "__main__":
    start_time = time.perf_counter()

    main()

    end_time = time.perf_counter()
    print(f"Elapsed run time: {end_time - start_time} seconds.")

Here, we used multiprocessing to calculate the prime numbers. 在这里,我们使用 multiprocessing 来计算素数。

Elapsed run time: 2.9848740599999997 seconds.

concurrent.futures Example concurrent.futures示例

# cpu-bound_parallel_2.py

import time
from concurrent.futures import ProcessPoolExecutor, wait
from multiprocessing import cpu_count

from tasks import get_prime_numbers

def main():
    futures = []

    with ProcessPoolExecutor(cpu_count() - 1) as executor:
        for num in range(1000, 16000):
            futures.append(executor.submit(get_prime_numbers, num))

    wait(futures)

if __name__ == "__main__":
    start_time = time.perf_counter()

    main()

    end_time = time.perf_counter()
    print(f"Elapsed run time: {end_time - start_time} seconds.")

Here, we achieved multiprocessing using concurrent.futures.ProcessPoolExecutor . Once the jobs are added to futures, wait(futures) waits for them to finish. 在这里,我们使用 concurrent.futures.ProcessPoolExecutor 实现了多处理。将作业添加到 future 后, wait(futures) 就会等待它们完成。

Elapsed run time: 4.452427557 seconds.

concurrent.futures.ProcessPoolExecutor is a wrapper around multiprocessing.Pool . It has the same limitations as the ThreadPoolExecutor . If you want more control over multiprocessing, use multiprocessing.Pool . concurrent.futures provides an abstraction over both multiprocessing and threading, making it easy to switch between the two. concurrent.futures.ProcessPoolExecutor multiprocessing.Pool 的包装器。它具有与 ThreadPoolExecutor 相同的限制。如果您想更好地控制多处理,请使用 multiprocessing.Pool concurrent.futures 提供了对多处理和线程的抽象,使得在两者之间切换变得容易。

Conclusion 结论

It’s worth noting that using multiprocessing to execute the make_request function will be much slower than the threading flavor since the processes will be need to wait for the IO. The multiprocessing approach will be faster then the sync approach, though. 值得注意的是,使用多进程来执行 make_request 函数将比线程的方式慢得多,因为进程需要等待 IO。不过,多进程方法还是会比同步方式更快。

Similarly, using concurrency for CPU-bound tasks is not worth the effort when compared to parallelism. 同样,与并行相比,对 CPU 密集型任务使用并发并不值得。

That being said, using concurrency or parallelism to execute your scripts adds complexity. Your code will generally be harder to read, test, and debug, so only use them when absolutely necessary for long-running scripts. 话虽这么说,使用并发或并行来执行脚本会增加复杂性。您的代码通常更难阅读、测试和调试,因此仅在长时间运行的脚本 绝对必要 时才使用它们。

concurrent.futures is where I generally start since- concurrent.futures 是我通常开始的地方,因为-

  1. It’s easy to switch back and forth between concurrency and parallelism
  2. 可以轻松地在并发和并行之间来回切换
  3. The dependent libraries don’t need to support asyncio ( requests vs httpx )
  4. 依赖库不需要支持 asyncio ( requests httpx
  5. It’s cleaner and easier to read over the other approaches
  6. 与其他方法相比,它更干净、更容易阅读

Grab the code from the parallel-concurrent-examples-python repo on GitHub. 从 GitHub 上的 parallel-concurrent-examples-python 存储库获取代码。

---------------------------END---------------------------

题外话

感谢你能看到最后,给大家准备了一些福利!

感兴趣的小伙伴,赠送全套Python学习资料,包含面试题、简历资料等具体看下方。


???? CSDN大礼包????: 全网最全《Python学习资料》免费赠送????! (安全链接,放心点击)

一、Python所有方向的学习路线

Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照下面的知识点去找对应的学习资源,保证自己学得较为全面。

img

二、Python兼职渠道推荐 *

学的同时助你创收,每天花1-2小时兼职,轻松稿定生活费.
在这里插入图片描述

三、最新Python学习笔记

当我学到一定基础,有自己的理解能力的时候,会去阅读一些前辈整理的书籍或者手写的笔记资料,这些笔记详细记载了他们对一些技术点的理解,这些理解是比较独到,可以学到不一样的思路。

img

四、实战案例

纸上得来终觉浅,要学会跟着视频一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。

img

???? CSDN大礼包????: 全网最全《Python学习资料》免费赠送????! (安全链接,放心点击)

若有侵权,请联系删除

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

用举例来学习Python中的并行性、并发性和异步性 的相关文章

  • 漂亮的地图打印机会抛出类型错误

    我已经使用配置了漂亮的打印机http wiki eclipse org CDT User FAQ How can I inspect the contents of STL containers 3F http wiki eclipse o
  • Python 函数句柄 ala Matlab

    在 MATLAB 中可以创建function handles http www mathworks co uk help techdoc ref function handle html与类似的东西 myfun arglist body 这
  • 在Python中不断寻找用户输入

    我将如何编写一个始终寻找用户输入的 Python 程序 我想我希望有一个等于输入的变量 然后根据该变量的等于值会发生不同的情况 因此 如果变量是 w 那么它将执行某个命令并继续执行 直到收到另一个输入 例如 d 然后会发生不同的情况 但直到
  • 如何将 Google Cloud Storage 中的许多文件设为私有?

    我进行了很多研究 但无法为此提出解决方案 以下是我用来在 GCP 中公开所有文件的代码 def make blob public bucket name blob name Makes a blob publicly accessible
  • Pygame 让精灵按照给定的旋转行走

    很久以前我做了一个Scratch脚本 我想用Pygame将其转换为Python 有很多示例显示图像的旋转 但我想知道如何更改精灵的旋转以使其沿给定方向移动 而不更改图像 这是我的暂存代码 这是我的 Pygame 精灵类 class Star
  • Seaborn regplot 中点和线的不同颜色

    中列出的所有示例西伯恩的regplot文档 https seaborn pydata org generated seaborn regplot html点和回归线显示相同的颜色 改变color争论改变了两者 如何为点设置与线不同的颜色 你
  • Colab 的使用限制持续多久?

    当我对同一帐户的两个笔记本同时使用两个 GPU 约半小时后 Colab 已 12 小时未运行 此消息不断弹出 由于 Colab 中的使用限制 您当前无法连接到 GPU 自从我上次使用 colab 以来已经过去了大约两个小时 但该消息仍然弹出
  • Django 说“id 可能不为 NULL”,但为什么会这样呢?

    我今天要疯了 我只是尝试插入一条新记录 但它返回了 post blogpost id 可能不为 NULL 错误 这是我的模型 class BlogPost models Model title models CharField max le
  • 监控培训课程如何运作?

    我试图理解使用之间的区别tf Session and tf train MonitoredTrainingSession 以及我可能更喜欢其中之一 似乎当我使用后者时 我可以避免许多 杂务 例如初始化变量 启动队列运行程序或设置文件编写器以
  • 如何在每次运行 python 程序时添加新列

    我希望我的表的第一列作为卷号 第二列作为名称 每当我运行 python 程序时 我想在表中添加一列日期 在这个新列中 我想填充从 user list 获得的列表将包含值 P A P P 等 如何处理 我尝试首先通过 alter 命令添加一列
  • 检查列表是否已排序的 Pythonic 方法

    有没有一种Python式的方法来检查列表是否已经排序ASC or DESC listtimestamps 1 2 3 5 6 7 就像是isttimestamps isSorted 返回True or False 我想输入一些消息的时间戳列
  • 将带有 md5 消息摘要和 DESede/CBC/PKCS5Padding 的 3DES 加密的 java 代码转换为 python

    我有这个工作java代码 它使用3DES加密对密码进行加密 import java security MessageDigest import java util Arrays import java util Base64 import
  • telethon 库:如何通过电话号码添加用户

    我正在研究 Telegram 的 Telethon 库 它可以使用 Telegram API 充当 Telegram 客户端 重要提示 这是电报客户端 API https core telegram org telegram api 而不是
  • 如何在自定义 django 命令中抽象出命令代码

    我正在我的应用程序下编写自定义 django 命令management commands目录 目前我在该目录中有 6 个不同的文件 每个文件都有不同的命令来解决独特的需求 然而 有一些实用程序是它们所共有的 抽象出这些公共代码的最佳方法是什
  • 如何使用 Python 实现并行 gzip 压缩?

    使用python压缩大文件 https stackoverflow com questions 9518705 big file compression with python给出了一个很好的例子来说明如何使用例如bz2 纯粹用 Pytho
  • 获取 python 模块的 2 个独立实例

    我正在与以非 OO 方式编写的 python 2 x API 进行交互 它使用模块全局范围来处理一些内部状态驱动的东西 在它不再是单例的情况下需要它 并且修改原始代码 不是我们的 不是一个选择 如果不使用单独解释器的子进程运行 有什么方法可
  • 跟踪白色背景中的白球(Python/OpenCV)

    我在 Python 3 中使用 OpenCV 来检测白场上的白 黑球 并给出它的精确 x y 半径 和颜色 我使用函数 cv2 Canny 和 cv2 findContours 来找到它 但问题是 cv2 Canny 并不总是检测到圆的完整
  • 如何从 python 中的字符串中删除 ANSI 转义序列

    这是包含我的字符串的片段 ls r n x1b 00m x1b 01 31mexamplefile zip x1b 00m r n x1b 01 31m 该字符串是从我执行的 SSH 命令返回的 我无法使用当前状态下的字符串 因为它包含 A
  • 如何从Python枚举类中获取所有值?

    我正在使用 Enum4 库创建一个枚举类 如下所示 class Color Enum RED 1 BLUE 2 我要打印 1 2 作为某处的列表 我怎样才能实现这个目标 您可以执行以下操作 e value for e in Color
  • 使用 python/scipy 进行 voronoi 和 lloyd 松弛

    如何使用 Qhull 确定哪些 voronoi 单元 按索引 是 正确的 由 现有顶点 组成 我正在尝试使用 LLoyds 算法和 scipy spatial Voronoi 它是 Qhull 的包装器 生成的输入来执行约束松弛 就代码而言

随机推荐

  • 鸿蒙开发 - Number和number、String和string等的区别

    我们知道鸿蒙开发使用的语言时 ArkTS 而 ArkTS 是 TypeScript 的超集 TypeScript 又是 JavaScript 的超集 所以对于基本数据类型使用的是 TypeScript 语法 在 TypeScript 中 N
  • python 必pass,这几个问题搞不明白,建议还是不要去面试了!

    1 可迭代对象 在 python 中我们可以通过 for 循环来遍历列表 元组 这种遍历我们称为迭代 Iteration 在 python 中凡是可以通过 for in 进行迭代的对象 它就是可迭代对象 1 1 如何判断一个对象是可迭代对象
  • 《LeetCode力扣练习》代码随想录——双指针法(翻转字符串里的单词---Java)

    LeetCode力扣练习 代码随想录 双指针法 翻转字符串里的单词 Java 刷题思路来源于 代码随想录 151 反转字符串中的单词 双指针 class Solution public String reverseWords String
  • linux中环境变量修改后只对当前终端生效,新的终端就失效了?

    环境变量修改后只对当前终端生效 新的终端就失效了 在 etc profile中最后添加了如下语句指定java环境变量 export JAVA HOME home local java jdk 17 0 9 9 export PATH JAV
  • 一文详解Python到底能做什么?

    声明 本篇文章的目的是介绍Python究竟可以用在多少个领域 以及它到底有多好用 有什么可用的工具包这一点上 以及对Python的相关管理环境和集成开发环境做一个简单的科普 没有任何包含适合于无脑按图配置操作的内容 需要这种内容可能还需要您
  • 华纳云:Ubuntu下LAMP环境如何配置

    在Ubuntu操作系统下配置LAMP环境 Linux Apache MySQL PHP 是一项常见的任务 特别是对于搭建Web服务器和运行PHP应用程序的场景 以下是在Ubuntu上配置LAMP环境的基本步骤 1 安装 Apache sud
  • 一文读懂易知微数字孪生实时云渲染技术

    实时云渲染是基于分布式GPU集群 提供音视频串流 应用云化的云端渲染平台 用户只需上传应用包 发布应用 访问链接三个步骤即可进行云端的渲染体验 适用于GPU渲染工作站 数字孪生以及AR VR MR等场景 PART1 云渲染与本地渲染的技术对
  • 开源不挣钱?这个项目上线半年月入超 30w

    很兴奋的告诉大家 Sealos 自从 6 月份上线以来 仅半年时间注册用户已经突破 7万 月收入超过 30w 本文来向大家介绍我们是怎么做开源商业化的 每月平均增速超过 40 而且这些收入大部分来自用户充值 或者是通过开源社区主动找到我们付
  • Windows7系统OptionalFeatures.exe文件丢失问题

    其实很多用户玩单机游戏或者安装软件的时候就出现过这种问题 如果是新手第一时间会认为是软件或游戏出错了 其实并不是这样 其主要原因就是你电脑系统的该dll文件丢失了或没有安装一些系统软件平台所需要的动态链接库 这时你可以下载这个Optiona
  • Windows7系统odbcconf.exe文件丢失问题

    其实很多用户玩单机游戏或者安装软件的时候就出现过这种问题 如果是新手第一时间会认为是软件或游戏出错了 其实并不是这样 其主要原因就是你电脑系统的该dll文件丢失了或没有安装一些系统软件平台所需要的动态链接库 这时你可以下载这个odbccon
  • 中企出海企业如何运用境外所得税收抵免消除双重征税影响?

    改革开放以来 中国企业不断创新出海模式 依托于人口红利的产品出口模式 中国成为了效率领先的全球制造工 厂 据工业和信息化部数据统计显示 2022年 我国制造业增加值占全球比重27 7 居世界首位 然而 当前国际政治与经济环境变幻莫测 全球贸
  • 深度解析Python爬虫中的隧道HTTP技术

    前言 网络爬虫在数据采集和信息搜索中扮演着重要的角色 然而 随着网站反爬虫的不断升级 爬虫机制程序面临着越来越多的挑战 隧道HTTP技术作为应对反爬虫机制的重要性手段 为爬虫程序提供了更为灵活和隐蔽的数据采集方式 本文将探讨Python爬虫
  • AI 时代,数智底座赋能企业智能运营

    作者 郑思宇 从云原生到生成式 AI 企业数智化跟随技术发展而不断升级的脚步从未停歇 但无论企业引入何种前沿技术 其能否取得丰硕的数智化应用成果 关键都在于这些技术创新能否真正理解企业业务 与业务融合的程度如何 因此 基于新技术的数智化创新
  • Windows7系统ntprint.exe文件丢失问题

    其实很多用户玩单机游戏或者安装软件的时候就出现过这种问题 如果是新手第一时间会认为是软件或游戏出错了 其实并不是这样 其主要原因就是你电脑系统的该dll文件丢失了或没有安装一些系统软件平台所需要的动态链接库 这时你可以下载这个ntprint
  • 这5个“计算机专业”就业很吃香,毕业生需求量大,还不会过时

    其实男生 尤其是理科生在选择专业的时候 如果实在是不知道该选择什么样的专业 可以推荐报考计算机类专业 因为大部分的男生其实对计算机类专业都不会怎么排斥 即便是有些课程不喜欢 但一些比较重要的专业课多数也不会真的讨厌 尽管计算机类专业对数学和
  • Axure之中继器的使用(交互&动作&reperter属性&Item属性)

    目录 一 中继器的基本使用 二 中继器的动作 增删改查 2 1 新增 2 2 删除 2 3 更新行 2 4 效果展示 2 5 模糊查询 三 reperter属性 在Axure中 中继器 Repeater 是一种功能强大的组件 用于 创建重复
  • 70个python练手项目 下载,python入门练手小程序

    大家好 小编来为大家解答以下问题 70个python练手项目百度网盘 70个python练手项目 下载 今天让我们一起来看看吧 今天博主给大家带来了一份大礼 Python爬虫70例 以及完整的项目源码 本文下面所有的爬虫项目都有详细的配套教
  • 公抓抓:批量获取企业工商信息的办法

    网站产生数据的作用 企业公示系统的数据 目前网络上每天都有海量数据诞生 这些数据蕴含着巨大的价值 很多时候企业和政府都需要大量的企业数据用于自身的运营 分析等 这些时候往往需要全面的数据才能得出更加客观的结论 比如金融机构在进行业务合作时
  • python——异常机制及常见异常汇总

    异常机制本质 异常指程序运行过程中出现的非正常现象 例如用户输入错误 除数为零 需 要处理的文件不存在 数组下标越界等 所谓异常处理 就是指程序在出现问题时依然可以正确的执行剩余的程序 而 不会因为异常而终止程序执行 python 中 引进
  • 用举例来学习Python中的并行性、并发性和异步性

    Parallelism Concurrency and AsyncIO in Python by example 用举例来学习Python中的并行性 并发性和异步性 一篇中文译文 来自 Parallelism Concurrency and