[D]我想在python跑多线程之前查看和修改默认线程的栈大小是调用什么方法

bullswu 2012-05-06 06:50:57
之前在网上我看到了一些资料,但是我还是get不到python的当前线程栈大小.请问有什么方法可以查找和设置栈的大小?

想突破线程的瓶颈,所以我想减小栈的大小,还有能否把堆的空间也用上,谢谢了.
-------------------------------
Double行动:
原帖分数:60
帖子加分:60
...全文
249 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
bugs2k 2012-05-07
  • 打赏
  • 举报
回复
class ThreadTests(BaseTestCase):

# Create a bunch of threads, let each do some work, wait until all are
# done.
def test_various_ops(self):
# This takes about n/3 seconds to run (about n/3 clumps of tasks,
# times about 1 second per clump).
NUMTASKS = 10

# no more than 3 of the 10 can run at once
sema = threading.BoundedSemaphore(value=3)
mutex = threading.RLock()
numrunning = Counter()

threads = []

for i in range(NUMTASKS):
t = TestThread("<thread %d>"%i, self, sema, mutex, numrunning)
threads.append(t)
self.assertEqual(t.ident, None)
self.assertTrue(re.match('<TestThread\(.*, initial\)>', repr(t)))
t.start()

if verbose:
print 'waiting for all tasks to complete'
for t in threads:
t.join(NUMTASKS)
self.assertTrue(not t.is_alive())
self.assertNotEqual(t.ident, 0)
self.assertFalse(t.ident is None)
self.assertTrue(re.match('<TestThread\(.*, \w+ -?\d+\)>', repr(t)))
if verbose:
print 'all tasks done'
self.assertEqual(numrunning.get(), 0)

def test_ident_of_no_threading_threads(self):
# The ident still must work for the main thread and dummy threads.
self.assertFalse(threading.currentThread().ident is None)
def f():
ident.append(threading.currentThread().ident)
done.set()
done = threading.Event()
ident = []
thread.start_new_thread(f, ())
done.wait()
self.assertFalse(ident[0] is None)
# Kill the "immortal" _DummyThread
del threading._active[ident[0]]

# run with a small(ish) thread stack size (256kB)
def test_various_ops_small_stack(self):
if verbose:
print 'with 256kB thread stack size...'
try:
threading.stack_size(262144)
except thread.error:
if verbose:
print 'platform does not support changing thread stack size'
return
self.test_various_ops()
threading.stack_size(0)

# run with a large thread stack size (1MB)
def test_various_ops_large_stack(self):
if verbose:
print 'with 1MB thread stack size...'
try:
threading.stack_size(0x100000)
except thread.error:
if verbose:
print 'platform does not support changing thread stack size'
return
self.test_various_ops()
threading.stack_size(0)
bullswu 2012-05-07
  • 打赏
  • 举报
回复
以上那个函数我也看了,具体是如何使用

在我执行线程之前执行这个函数就可以了?
threading.stack_size(32,768 )
bugs2k 2012-05-07
  • 打赏
  • 举报
回复
32kB is currently the minimum supported stack size value to guarantee sufficient stack space for the interpreter itself
bullswu 2012-05-07
  • 打赏
  • 举报
回复
我按照这个方法设置,在执行线程前设置threading.stack_size(32*1024),然后在我的线程里面while做了循环之后第一次打印是32k的线程,但是第二次确是0,后面几次都这样..

虽然我原来的方法其实通过了别的方式加了线程数,不过还是想搞清楚:
python的线程的堆栈是不是最低只能32*10240?同时也是默认的栈值是32k么?

还有为什么按照你那样使用后第二次循环了却打印0,这是默认的意思还是别的意思.?
bugs2k 2012-05-06
  • 打赏
  • 举报
回复
threading.stack_size([size])
Return the thread stack size used when creating new threads. The optional size argument specifies the stack size to be used for subsequently created threads, and must be 0 (use platform or configured default) or a positive integer value of at least 32,768 (32kB). If changing the thread stack size is unsupported, a ThreadError is raised. If the specified stack size is invalid, a ValueError is raised and the stack size is unmodified. 32kB is currently the minimum supported stack size value to guarantee sufficient stack space for the interpreter itself. Note that some platforms may have particular restrictions on values for the stack size, such as requiring a minimum stack size > 32kB or requiring allocation in multiples of the system memory page size - platform documentation should be referred to for more information (4kB pages are common; using multiples of 4096 for the stack size is the suggested approach in the absence of more specific information). Availability: Windows, systems with POSIX threads.

New in version 2.5.
内容概要:本文档围绕“四杆机构分析”展开,介绍了一种基于给定系统几何参数执行四杆机构运动学分析的研究方法,并提供了完整的Matlab代码实现。四杆机构作为机械系统中的经典【四杆机构分析】根据给定的系统几何参数执行四杆机构分析研究(Matlab代码实现)连杆机构,其运动特性分析在自动化、机器人、车辆工程等领域具有重要应用价值。文档内容涵盖机构的位置、速度和加速度分析,通过矢量闭环法建立数学模型,利用Matlab进行数值计算与可视化仿真,帮助用户理解机构的运动规律。此外,文档还展示了代码的模块化结构,便于扩展至其他连杆机构分析。; 适合人群:具备一定Matlab编程基础和机械原理知识的本科高年级学生、研究生及从事机械系统仿真与设计的工程技术人员。; 使用场景及目标:①掌握四杆机构的运动学建模方法;②学习如何使用Matlab实现机构的位姿分析与动态仿真;③为后续复杂机构设计与机器人运动学研究打下基础;④适用于课程设计、科研项目或工程验证中的机构分析任务。; 阅读建议:建议读者结合机械原理教材中的四杆机构理论,逐步调试Matlab代码,观察各参数变化对机构运动的影响,并尝试修改几何参数或扩展至多连杆系统,以加深对运动学分析的理解。
内容概要:本文介绍了一个基于多传感器融合的定位系统设计方案,采用GPS、里程计和电子罗盘作为定位传感器,利用扩展卡尔曼滤波(EKF)算法对多源传感器数据进行融合处理,最终输出目标的滤波后位置信息,并提供了完整的Matlab代码实现。该方法有效提升了定位精度与稳定性,尤其适用于存在单一传感器误差或信号丢失的复杂环境,如自动驾驶、移动采用GPS、里程计和电子罗盘作为定位传感器,EKF作为多传感器的融合算法,最终输出目标的滤波位置(Matlab代码实现)机器人导航等领域。文中详细阐述了各传感器的数据建模方式、状态转移与观测方程构建,以及EKF算法的具体实现步骤,具有较强的工程实践价值。; 适合人群:具备一定Matlab编程基础,熟悉传感器原理和滤波算法的高校研究生、科研人员及从事自动驾驶、机器人导航等相关领域的工程技术人员。; 使用场景及目标:①学习和掌握多传感器融合的基本理论与实现方法;②应用于移动机器人、无人车、无人机等系统的高精度定位与导航开发;③作为EKF算法在实际工程中应用的教学案例或项目参考; 阅读建议:建议读者结合Matlab代码逐行理解算法实现过程,重点关注状态预测与观测更新模块的设计逻辑,可尝试引入真实传感器数据或仿真噪声环境以验证算法鲁棒性,并进一步拓展至UKF、PF等更高级滤波算法的研究与对比。
内容概要:文章围绕智能汽车新一代传感器的发展趋势,重点阐述了BEV(鸟瞰图视角)端到端感知融合架构如何成为智能驾驶感知系统的新范式。传统后融合与前融合方案因信息丢失或算力需求过高难以满足高阶智驾需求,而基于Transformer的BEV融合方案通过统一坐标系下的多源传感器特征融合,在保证感知精度的同时兼顾算力可行性,显著提升复杂场景下的鲁棒性与系统可靠性。此外,文章指出BEV模型落地面临大算力依赖与高数据成本的挑战,提出“数据采集-模型训练-算法迭代-数据反哺”的高效数据闭环体系,通过自动化标注与长尾数据反馈实现算法持续进化,降低对人工标注的依赖,提升数据利用效率。典型企业案例进一步验证了该路径的技术可行性与经济价值。; 适合人群:从事汽车电子、智能驾驶感知算法研发的工程师,以及关注自动驾驶技术趋势的产品经理和技术管理者;具备一定自动驾驶基础知识,希望深入了解BEV架构与数据闭环机制的专业人士。; 使用场景及目标:①理解BEV+Transformer为何成为当前感知融合的主流技术路线;②掌握数据闭环在BEV模型迭代中的关键作用及其工程实现逻辑;③为智能驾驶系统架构设计、传感器选型与算法优化提供决策参考; 阅读建议:本文侧重技术趋势分析与系统级思考,建议结合实际项目背景阅读,重点关注BEV融合逻辑与数据闭环构建方法,并可延伸研究相关企业在舱泊一体等场景的应用实践。

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧