为什么python没有垃圾收集器线程? [英] Why python doesn't have Garbage Collector thread?
问题描述
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $'$'$ ]
java.lang.Thread.sleep的
(原生方法)
....
GC任务线程#
java.lang.Thread.State:TIMED_WAITING(sleeping) 0(ParallelGC)os_prio = 0 tid = 0x00007f34b0023000 nid = 0x809 runnable
GC任务线程#1(ParallelGC)os_prio = 0 tid = 0x00007f34b0024800 nid = 0x80a可运行
GC任务线程#2 ParallelGC)os_prio = 0 tid = 0x00007f34b0026800 nid = 0x80b runnable
但是在谈到python时,我写了一篇
$ b $ pre $
#!/ usr / bin / env python
导入gc
导入时间
gc .enable()
,而True:
print每分钟打印一次。
time.sleep(60)
我看到python进程只有一个线程,
$ cat / proc / 1627 / status
名称:python
...
线程:1
问题是,为什么python没有像Java那样的gc线程?然后哪个线程执行gc任务?
如果您使用 -XX启动java:+ UseSerialGC
选项,您将看不到任何GC线程。
对于单线程GC算法,应用程序线程可用于执行GC活动。
所需的专用线程 Java has daemon thread to monitor memory usage and do the gc task. From jstack I see But speaking of python, I wrote a I saw the the python process has only one thread, The question is, why python doesn't have gc thread like Java? Then which thread does the gc task? If you start java with Dedicated threads required for 这篇关于为什么python没有垃圾收集器线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
并行GC(您需要多于单线程)
"main" #1 prio=5 os_prio=0 tid=0x00007f34b000e000 nid=0x808 waiting on condition [0x00007f34b6f02000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
....
"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007f34b0023000 nid=0x809 runnable
"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007f34b0024800 nid=0x80a runnable
"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00007f34b0026800 nid=0x80b runnable
#!/usr/bin/env python
import gc
import time
gc.enable()
while True:
print "This prints once a minute."
time.sleep(60)
$ cat /proc/1627/status
Name: python
...
Threads: 1
-XX:+UseSerialGC
options you will not see any GC thread.
For single threaded GC algorithm application thread can be used to do GC activities.