Python:运行时错误:无法启动新线程

问题描述 投票:0回答:1

我使用Python的资源库来限制我的资源


import resource


rsrc = resource.RLIMIT_DATA`
resource.setrlimit(rsrc, (150*1024*1024, 200*1024*1024))

我在发布消息时遇到了这个问题:

Exception in thread Thread-PubSubBatchCommitter:
Traceback (most recent call last):
    File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
        self.run()
    File "/usr/local/lib/python3.12/threading.py", line 1010, in run
        self._target(*self._args, **self._kwargs)
    File "/usr/local/lib/python3.12/site-packages/google/cloud/pubsub_v1/publisher/client.py", line 454, in _wait_and_commit_sequencers
        self._commit_sequencers()
    File "/usr/local/lib/python3.12/site-packages/google/cloud/pubsub_v1/publisher/client.py", line 468, in _commit_sequencers
        sequencer.commit()
    File "/usr/local/lib/python3.12/site-packages/google/cloud/pubsub_v1/publisher/_sequencer/unordered_sequencer.py", line 80, in commit
        self._current_batch.commit()
    File "/usr/local/lib/python3.12/site-packages/google/cloud/pubsub_v1/publisher/_batch/thread.py", line 217, in commit
        self._start_commit_thread()
    File "/usr/local/lib/python3.12/site-packages/google/cloud/pubsub_v1/publisher/_batch/thread.py", line 227, in _start_commit_thread
        commit_thread.start()
    File "/usr/local/lib/python3.12/threading.py", line 992, in start
        _start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread

我不明白为什么我会遇到

can't start new thread
当我限制资源时出现异常,我尝试增加硬限制,错误保持不变,但是当我增加软限制时,我没有收到错误

据我了解,当您的 python 进程中已经运行了太多线程,并且由于某种资源限制,创建新线程的请求被拒绝时,就会发生错误。

我尝试过使用

mprofile
,消耗的最高内存为68 Mib。有人可以向我解释一下幕后发生了什么吗?

python python-3.x multithreading resources
1个回答
0
投票

如果您遇到同样的问题,请搜索RLIMIT_DATA,这应该可以回答您的问题

这是进程数据段(已初始化数据、未初始化数据和堆)的最大大小。该限制以字节为单位指定,并向下舍入到系统页面大小。此限制会影响对 brk(2)、sbrk(2) 和(自 Linux 4.7 起)mmap(2) 的调用,这些调用在遇到此资源的软限制时会失败并显示错误 ENOMEM。

https://manpages.debian.org/buster/manpages-dev/getrlimit.2.en.html

© www.soinside.com 2019 - 2024. All rights reserved.