PyTorch DataLoader 报错 “DataLoader worker exited unexpectedly“ 的解决方案

注意:博主没有重写d2l的源代码文件,而是创建了一个新的python文件,并重写了该方法。

一、代码运行日志

C:\Users\Administrator\anaconda3\envs\limu\python.exe G:/PyCharmProjects/limu-d2l/ch03/softmax_regression.py
Traceback (most recent call last):File "<string>", line 1, in <module>
Traceback (most recent call last):File "<string>", line 1, in <module>File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 116, in spawn_mainFile "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 116, in spawn_mainexitcode = _main(fd, parent_sentinel)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 125, in _mainTraceback (most recent call last):
exitcode = _main(fd, parent_sentinel)File "<string>", line 1, in <module>File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 125, in _main
Traceback (most recent call last):File "<string>", line 1, in <module>
prepare(preparation_data)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 236, in prepareprepare(preparation_data)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 236, in prepare_fixup_main_from_path(data['init_main_from_path'])File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path_fixup_main_from_path(data['init_main_from_path'])File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_pathmain_content = runpy.run_path(main_path,File "C:\Users\Administrator\anaconda3\envs\limu\lib\runpy.py", line 265, in run_pathmain_content = runpy.run_path(main_path,File "C:\Users\Administrator\anaconda3\envs\limu\lib\runpy.py", line 265, in run_pathreturn _run_module_code(code, init_globals, run_name,File "C:\Users\Administrator\anaconda3\envs\limu\lib\runpy.py", line 97, in _run_module_codereturn _run_module_code(code, init_globals, run_name,File "C:\Users\Administrator\anaconda3\envs\limu\lib\runpy.py", line 97, in _run_module_code_run_code(code, mod_globals, init_globals,File "C:\Users\Administrator\anaconda3\envs\limu\lib\runpy.py", line 87, in _run_code_run_code(code, mod_globals, init_globals,File "C:\Users\Administrator\anaconda3\envs\limu\lib\runpy.py", line 87, in _run_codeFile "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 116, in spawn_mainFile "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 116, in spawn_mainexec(code, run_globals)File "G:\PyCharmProjects\limu-d2l\ch03\softmax_regression.py", line 97, in <module>
exec(code, run_globals)File "G:\PyCharmProjects\limu-d2l\ch03\softmax_regression.py", line 97, in <module>train_ch03(net, train_iter, test_iter, cross_entropy, num_epochs, updater)File "G:\PyCharmProjects\limu-d2l\ch03\softmax_regression.py", line 81, in train_ch03
exitcode = _main(fd, parent_sentinel)
train_ch03(net, train_iter, test_iter, cross_entropy, num_epochs, updater)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 125, in _mainFile "G:\PyCharmProjects\limu-d2l\ch03\softmax_regression.py", line 81, in train_ch03exitcode = _main(fd, parent_sentinel)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 125, in _maintrain_loss, train_acc = train_epoch_ch03(net, train_iter, loss, updater)train_loss, train_acc = train_epoch_ch03(net, train_iter, loss, updater)File "G:\PyCharmProjects\limu-d2l\ch03\softmax_regression.py", line 64, in train_epoch_ch03File "G:\PyCharmProjects\limu-d2l\ch03\softmax_regression.py", line 64, in train_epoch_ch03prepare(preparation_data)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 236, in prepareprepare(preparation_data)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 236, in preparefor X, y in train_iter:for X, y in train_iter:File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 441, in __iter__File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 441, in __iter___fixup_main_from_path(data['init_main_from_path'])_fixup_main_from_path(data['init_main_from_path'])File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_pathFile "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_pathmain_content = runpy.run_path(main_path,main_content = runpy.run_path(main_path,File "C:\Users\Administrator\anaconda3\envs\limu\lib\runpy.py", line 265, in run_pathFile "C:\Users\Administrator\anaconda3\envs\limu\lib\runpy.py", line 265, in run_pathreturn self._get_iterator()File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 388, in _get_iteratorreturn self._get_iterator()File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 388, in _get_iteratorreturn _run_module_code(code, init_globals, run_name,return _run_module_code(code, init_globals, run_name,File "C:\Users\Administrator\anaconda3\envs\limu\lib\runpy.py", line 97, in _run_module_codeFile "C:\Users\Administrator\anaconda3\envs\limu\lib\runpy.py", line 97, in _run_module_codereturn _MultiProcessingDataLoaderIter(self)File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 1042, in __init__return _MultiProcessingDataLoaderIter(self)File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 1042, in __init___run_code(code, mod_globals, init_globals,    
_run_code(code, mod_globals, init_globals,File "C:\Users\Administrator\anaconda3\envs\limu\lib\runpy.py", line 87, in _run_codeFile "C:\Users\Administrator\anaconda3\envs\limu\lib\runpy.py", line 87, in _run_codeexec(code, run_globals)    
exec(code, run_globals)File "G:\PyCharmProjects\limu-d2l\ch03\softmax_regression.py", line 97, in <module>File "G:\PyCharmProjects\limu-d2l\ch03\softmax_regression.py", line 97, in <module>train_ch03(net, train_iter, test_iter, cross_entropy, num_epochs, updater)File "G:\PyCharmProjects\limu-d2l\ch03\softmax_regression.py", line 81, in train_ch03
train_ch03(net, train_iter, test_iter, cross_entropy, num_epochs, updater)File "G:\PyCharmProjects\limu-d2l\ch03\softmax_regression.py", line 81, in train_ch03w.start()File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\process.py", line 121, in startw.start()File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\process.py", line 121, in starttrain_loss, train_acc = train_epoch_ch03(net, train_iter, loss, updater)train_loss, train_acc = train_epoch_ch03(net, train_iter, loss, updater)File "G:\PyCharmProjects\limu-d2l\ch03\softmax_regression.py", line 64, in train_epoch_ch03File "G:\PyCharmProjects\limu-d2l\ch03\softmax_regression.py", line 64, in train_epoch_ch03self._popen = self._Popen(self)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\context.py", line 224, in _Popenfor X, y in train_iter:for X, y in train_iter:File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 441, in __iter__File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 441, in __iter__self._popen = self._Popen(self)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\context.py", line 224, in _Popenreturn _default_context.get_context().Process._Popen(process_obj)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\context.py", line 327, in _Popenreturn _default_context.get_context().Process._Popen(process_obj)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\context.py", line 327, in _Popenreturn self._get_iterator()return self._get_iterator()File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 388, in _get_iteratorFile "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 388, in _get_iteratorreturn Popen(process_obj)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__return Popen(process_obj)            return _MultiProcessingDataLoaderIter(self)return _MultiProcessingDataLoaderIter(self)prep_data = spawn.get_preparation_data(process_obj._name)File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 1042, in __init__File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 1042, in __init__File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 154, in get_preparation_dataFile "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__prep_data = spawn.get_preparation_data(process_obj._name)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_check_not_importing_main()File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main_check_not_importing_main()File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_mainraise RuntimeError('''
RuntimeError: An attempt has been made to start a new process before thecurrent process has finished its bootstrapping phase.This probably means that you are not using fork to start yourchild processes and you have forgotten to use the proper idiomin the main module:if __name__ == '__main__':freeze_support()...The "freeze_support()" line can be omitted if the programis not going to be frozen to produce an executable.w.start()File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\process.py", line 121, in startw.start()File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\process.py", line 121, in startraise RuntimeError('''
RuntimeError: An attempt has been made to start a new process before thecurrent process has finished its bootstrapping phase.This probably means that you are not using fork to start yourchild processes and you have forgotten to use the proper idiomin the main module:if __name__ == '__main__':freeze_support()...The "freeze_support()" line can be omitted if the programis not going to be frozen to produce an executable.self._popen = self._Popen(self)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\context.py", line 224, in _Popenself._popen = self._Popen(self)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\context.py", line 224, in _Popenreturn _default_context.get_context().Process._Popen(process_obj)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\context.py", line 327, in _Popen
return _default_context.get_context().Process._Popen(process_obj)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\context.py", line 327, in _Popenreturn Popen(process_obj)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__return Popen(process_obj)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__prep_data = spawn.get_preparation_data(process_obj._name)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 154, in get_preparation_dataprep_data = spawn.get_preparation_data(process_obj._name)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 154, in get_preparation_data_check_not_importing_main()File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main_check_not_importing_main()File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_mainraise RuntimeError('''raise RuntimeError('''
RuntimeError: RuntimeErrorAn attempt has been made to start a new process before thecurrent process has finished its bootstrapping phase.This probably means that you are not using fork to start yourchild processes and you have forgotten to use the proper idiomin the main module:if __name__ == '__main__':freeze_support()...The "freeze_support()" line can be omitted if the programis not going to be frozen to produce an executable.: An attempt has been made to start a new process before thecurrent process has finished its bootstrapping phase.This probably means that you are not using fork to start yourchild processes and you have forgotten to use the proper idiomin the main module:if __name__ == '__main__':freeze_support()...The "freeze_support()" line can be omitted if the programis not going to be frozen to produce an executable.
Traceback (most recent call last):File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 1132, in _try_get_datadata = self._data_queue.get(timeout=timeout)File "C:\Users\Administrator\anaconda3\envs\limu\lib\multiprocessing\queues.py", line 108, in getraise Empty
_queue.EmptyThe above exception was the direct cause of the following exception:Traceback (most recent call last):File "G:/PyCharmProjects/limu-d2l/ch03/softmax_regression.py", line 97, in <module>train_ch03(net, train_iter, test_iter, cross_entropy, num_epochs, updater)File "G:/PyCharmProjects/limu-d2l/ch03/softmax_regression.py", line 81, in train_ch03train_loss, train_acc = train_epoch_ch03(net, train_iter, loss, updater)File "G:/PyCharmProjects/limu-d2l/ch03/softmax_regression.py", line 64, in train_epoch_ch03for X, y in train_iter:File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 633, in __next__data = self._next_data()File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 1328, in _next_dataidx, data = self._get_data()File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 1294, in _get_datasuccess, data = self._try_get_data()File "C:\Users\Administrator\anaconda3\envs\limu\lib\site-packages\torch\utils\data\dataloader.py", line 1145, in _try_get_dataraise RuntimeError('DataLoader worker (pid(s) {}) exited unexpectedly'.format(pids_str)) from e
RuntimeError: DataLoader worker (pid(s) 14032, 23312, 21048, 1952) exited unexpectedlyProcess finished with exit code 1

二、问题分析

这个错误是由于在使用多进程 DataLoader 时出现的问题,通常与 Windows 操作系统相关。在 Windows 上,使用多进程的 DataLoader 可能会导致一些问题,这与 Windows 的进程模型不太兼容。

三、解决方案(使用单进程 DataLoader)

在 Windows 上,将 DataLoader 的 num_workers 参数设置为 0,以使用单进程 DataLoader。这会禁用多进程加载数据,虽然可能会导致数据加载速度变慢,但通常可以解决与多进程 DataLoader 相关的问题。

d2l.load_data_fashion_mnist(batch_size)源代码

def get_dataloader_workers():"""Use 4 processes to read the data.Defined in :numref:`sec_utils`"""return 4def load_data_fashion_mnist(batch_size, resize=None):"""Download the Fashion-MNIST dataset and then load it into memory.Defined in :numref:`sec_utils`"""trans = [transforms.ToTensor()]if resize:trans.insert(0, transforms.Resize(resize))trans = transforms.Compose(trans)mnist_train = torchvision.datasets.FashionMNIST(root="../data", train=True, transform=trans, download=True)mnist_test = torchvision.datasets.FashionMNIST(root="../data", train=False, transform=trans, download=True)return (torch.utils.data.DataLoader(mnist_train, batch_size, shuffle=True,num_workers=get_dataloader_workers()),torch.utils.data.DataLoader(mnist_test, batch_size, shuffle=False,num_workers=get_dataloader_workers()))

在代码中使用修改后的load_data_fashion_mnist函数

def load_data_fashion_mnist(batch_size, resize=None, num_workers=4):"""下载Fashion-MNIST数据集,然后将其加载到内存中"""trans = [transforms.ToTensor()]if resize:trans.index(0, transforms.Resize(resize))trans = transforms.Compose(trans)mnist_train = torchvision.datasets.FashionMNIST(root='../data', train=True, transform=trans, download=True)mnist_test = torchvision.datasets.FashionMNIST(root='../data', train=False, transform=trans, download=True)return (data.DataLoader(mnist_train, batch_size, shuffle=True, num_workers=num_workers),data.DataLoader(mnist_test, batch_size, shuffle=False, num_workers=num_workers))
train_iter, test_iter = fashion_mnist.load_data_fashion_mnist(batch_size, num_workers=0)

在这里插入图片描述

四、为什么将 DataLoader 的 num_workers 参数设置为 0,是使用的单进程,而不是零进程呢?

在 PyTorch 的 DataLoader 中,num_workers 参数控制了用于加载数据的子进程数量。当 num_workers 被设置为 0 时,实际上是表示不使用任何子进程来加载数据,即单进程加载数据。

为什么不是零进程?这是因为 DataLoader 需要至少一个进程来加载数据,这个进程被称为主进程。主进程负责数据加载和分发给训练的进程。当 num_workers 设置为 0 时,只有主进程用于加载和处理数据,没有额外的子进程。这是一种单进程的数据加载方式。

如果将 num_workers 设置为 1,则会有一个额外的子进程来加载数据,总共会有两个进程:一个主进程和一个数据加载子进程。这种设置可以在某些情况下提高数据加载的效率,特别是当数据加载耗时较长时,子进程可以并行地加载数据,从而加速训练过程。

五、完整训练代码

import torch
from d2l import torch as d2l
import fashion_mnistbatch_size = 256
train_iter, test_iter = fashion_mnist.load_data_fashion_mnist(batch_size, num_workers=0)# 初始化模型参数
num_inputs = 784  # 每个输入图像的通道数为1, 高度和宽度均为28像素
num_outputs = 10W = torch.normal(0, 0.01, size=(num_inputs, num_outputs), requires_grad=True)
b = torch.zeros(num_outputs, requires_grad=True)# 定义softmax操作
def softmax(X):"""矩阵中的非常大或非常小的元素可能造成数值上溢或者下溢解决方案: P84 3.7.2 重新审视softmax的实现"""X_exp = torch.exp(X)partition = X_exp.sum(1, keepdim=True)return X_exp / partition# 定义模型
def net(X):return softmax(torch.matmul(X.reshape((-1, W.shape[0])), W) + b)# 定义损失函数
def cross_entropy(y_hat, y):return - torch.log(y_hat[range(len(y_hat)), y])# 分类精度
def accuracy(y_hat, y):"""计算预测正确的数量"""if len(y_hat.shape) > 1 and y_hat.shape[1] > 1:y_hat = y_hat.argmax(axis=1)cmp = y_hat.type(y.dtype) == yreturn float(cmp.type(y.dtype).sum())def evaluate_accuracy(net, data_iter):"""计算在制定数据集上模型的精度"""if isinstance(net, torch.nn.Module):net.eval()metric = d2l.Accumulator(2)with torch.no_grad():for X, y in data_iter:metric.add(accuracy(net(X), y), y.numel())return metric[0] / metric[1]# 训练
def train_epoch_ch03(net, train_iter, loss, updater):if isinstance(net, torch.nn.Module):net.train()# 训练损失总和, 训练准确度总和, 样本数metric = d2l.Accumulator(3)for X, y in train_iter:y_hat = net(X)l = loss(y_hat, y)if isinstance(updater, torch.optim.Optimizer):updater.zero_grad()l.mean().backward()updater.step()else:l.sum().backward()updater(X.shape[0])metric.add(float(l.sum()), accuracy(y_hat, y), y.numel())# 返回训练损失和训练精度return metric[0] / metric[2], metric[1] / metric[2]def train_ch03(net, train_iter, test_iter, loss, num_epochs, updater):for epoch in range(num_epochs):train_loss, train_acc = train_epoch_ch03(net, train_iter, loss, updater)test_acc = evaluate_accuracy(net, test_iter)print(f'epoch {epoch + 1}, train_loss {train_loss:f}, train_acc {train_acc:f}, test_acc {test_acc:f}')assert train_loss < 0.5, train_lossassert train_acc <= 1 and train_acc > 0.7, train_accassert test_acc <= 1 and test_acc > 0.7, test_acclr = 0.1def updater(batch_size):return d2l.sgd([W, b], lr, batch_size)num_epochs = 10
train_ch03(net, train_iter, test_iter, cross_entropy, num_epochs, updater)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/51767.shtml

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

相关文章

通过python在unity里调用C#接口

log: 背景 最近在做虚拟人底层驱动sdk测试&#xff0c;因为后端使用的是C#,我个人更倾向于python编程辅助测试工作&#xff0c;测试sdk需要通过开发提供的接口方法文档&#xff0c;通过传测试场景参数调用方法进行单元测试 技术&工具 项目语言 C# 项目工具 unity 测试…

Word怎么转换成PDF文档?多个Word转换成PDF步骤分享

word文档是一种非常好用的文件格式&#xff0c;可以帮助用户们很好的保存图片和文字内容&#xff0c;不过并不是只有word这一种文档类文件格式&#xff0c;还有一种pdf文档也深受用户们的欢迎&#xff0c;在工作或者学习过程中这两种文档是可以互相转换格式的&#xff0c;那么W…

Spark项目Java和Scala混合打包编译

文章目录 项目结构Pom完整文件编译查看 实际开发用有时候引用自己写的一些java工具类&#xff0c;但是整个项目是scala开发的spark程序&#xff0c;在项目打包时需要考虑到java和scala混合在一起编译。 今天看到之前很久之前写的一些打包编译文章&#xff0c;发现很多地方不太对…

springboot+docker实现微服务的小例子

【任务】&#xff1a; 创建一个服务A&#xff1a;service_hello 创建一个服务B&#xff1a;service_name service_name负责提供一个api接口返回一个name字符串。 service_hello负责从这个接口获取name字符串&#xff0c;然后进行一个字符串拼接&#xff0c;在后面加一个hello&…

基于flask的python和C#的联合调用3

一、c#的jeson的解析 1.1 下载c#能够调用的jeson的dll库 将动态库&#xff0c;引用添加。 将c#的主文件中&#xff0c;添加头文件 using Newtonsoft.Json; using Newtonsoft.Json.Converters;

Go语言里面的各种疑难杂症

什么是闭包&#xff1f;闭包有什么缺陷&#xff1f; func AddUpper() func(int)int{var n int 10return func (x int) int{n nxreturn n} }func main(){f : AddUpper()fmt.Println(f(1))//11fmt.Println(f(2))//13fmt.Println(f(3))//16 }&#xff08;1&#xff09; AddUpper…

重排链表(C语言)

题目&#xff1a; 示例&#xff1a; 思路&#xff1a; 这题我们将使用栈解决这个问题&#xff0c;利用栈先进后出的特点&#xff0c;从链表的中间位置进行入栈&#xff0c;寻找链表的中间位置参考&#xff1a;删除链表的中间节点&#xff0c;之后从头开始进行连接。 本题使用…

【C++】异常

异常 前言正式开始C语言传统的处理错误的方式C异常概念异常的使用异常的抛出和捕获自定义异常体系实际中的应用异常的重新抛出 异常安全异常规范C标准库的异常体系异常的优缺点 前言 从这篇开始&#xff0c;我后面的几篇可以算是C的收尾了。 本篇讲异常。 正式开始 先说说C…

MyBatis分页插件PageHelper的使用及特殊字符的处理

目录 一、PageHelper简介 1.什么是分页 2.PageHelper是什么 3.使用PageHelper的优点 二、PageHelper插件的使用 原生limit查询 1. 导入pom依赖 2. Mybatis.cfg.xml 配置拦截器 3. 使用PageHelper进行分页 三、特殊字符的处理 1.SQL注入&#xff1a; 2.XML转义&#…

Arduino程序设计(四)按键消抖+按键计数

按键消抖按键计数 前言一、按键消抖二、按键计数1、示例代码2、按键计数实验 参考资料 前言 本文主要介绍两种按键控制LED实验&#xff1a;第一种是采用软件消抖的方法检测按键按下的效果&#xff1b;第二种是根据按键按下次数&#xff0c;四个LED灯呈现不同的流水灯效果。 一…

什么是负载均衡

前提概述 关于负载均衡&#xff0c;我会从四个方面去说 1. 负载均衡产生的背景 2. 负载均衡的实现技术 3. 负载均衡的作用范围 4. 负载均衡的常用算法 负载均衡的诞生背景 在互联网发展早期&#xff0c;由于用户量较少、业务需求也比较简单。对于软件应用&#xff0c;我们只需要…

《Zookeeper》源码分析(二十)之 Follower

目录 Follower创建Follower实例followLeader()findLeader()connectToLeader()registerWithLeader()syncWithLeader() FollowerZooKeeperServer Follower Leader选举结束后&#xff0c;成为Follower的服务器开始进行Follower的工作&#xff0c;过程如下&#xff1a; 与Leader…

计算机终端核心安全配置规范

声明 本文是学习 政务计算机终端核心配置规范. 而整理的学习笔记,分享出来希望更多人受益,如果存在侵权请及时联系我们 范围 本标准提出了政务计算机终端核心配置的基本概念和要求&#xff0c;规定了核心配置的自动化实现方法&#xff0c;规范了核心配置实施流程。 本标准适…

【Terraform学习】使用 Terraform 创建Amazon VPC(Terraform-AWS最佳实战学习)

使用 Terraform 创建Amazon VPC 实验步骤 前提条件 安装 Terraform&#xff1a; 地址 下载仓库代码模版 本实验代码位于 task_vpc 文件夹中。 变量文件 variables.tf 在上面的代码中&#xff0c;您将声明&#xff0c;aws_access_key&#xff0c;aws_secret_key和 区域变量…

Linux搭建SSLVpn

安装http、ssl服务 编辑http配置文件 修改http的136行&#xff0c;276行以及990行 1、136行将监听端口注释 2、276行和990行修改为自己的域名和要访问的端口 修改http文档最后那部分 新添ssl配置信息&#xff0c;将端口修改为443&#xff08;截图错了server.key应该放在/etc/…

jenkins Linux如何修改jenkins 默认的工作空间workspace

由于jenkins默认存放数据的目录是/var/lib/jenkins&#xff0c;一般这个var目录的磁盘空间很小的&#xff0c;就几十G,所以需要修改jenkins的默认工作空间workspace 环境 jenkins使用yum安装的 centos 7 正题 1 查看jenkins安装路径 [rootlocalhost jenkins_old_data]# rpm…

【80天学习完《深入理解计算机系统》】第九天 3.2 数据传送指令【mov】【栈和堆】【leaq】【一元操作】【二元操作】

专注 效率 记忆 预习 笔记 复习 做题 欢迎观看我的博客&#xff0c;如有问题交流&#xff0c;欢迎评论区留言&#xff0c;一定尽快回复&#xff01;&#xff08;大家可以去看我的专栏&#xff0c;是所有文章的目录&#xff09;   文章字体风格&#xff1a; 红色文字表示&#…

基于AWS的3D模型搜索服务实现

3D模型广泛应用于计算机游戏、电影、工程、零售业、广告等许多领域。市场上有很多制作3D模型的工具&#xff0c;但几乎没有工具可以直观地搜索3D模型数据库以找到类似的3D模型 因为开发好的 3D 模型搜索工具非常具有挑战性。 它需要复杂的计算和 AI/ML 框架来创建模型描述符并提…

【MySQL系列】Select语句单表查询详解(二)ORDERBY排序

&#x1f490; &#x1f338; &#x1f337; &#x1f340; &#x1f339; &#x1f33b; &#x1f33a; &#x1f341; &#x1f343; &#x1f342; &#x1f33f; &#x1f344;&#x1f35d; &#x1f35b; &#x1f364; &#x1f4c3;个人主页 &#xff1a;阿然成长日记 …

C语言:选择+编程(每日一练Day8)

目录 选择题&#xff1a; 题一&#xff1a; 题二&#xff1a; 题三&#xff1a; 题四&#xff1a; 题五&#xff1a; 编程题&#xff1a; 题一&#xff1a;字符个数统计 思路一&#xff1a; 题二&#xff1a;多数元素 思路一&#xff1a; 本人实力有限可能对一些…