考虑下面这段代码:
l = []
while 1
l << 'a random 369-characterish string'
end
^C
# ran this for maybe 4 seconds, and it had 27 million entries in l. memory
# usage was 1.6 GB.
l = nil
# no change in memory usage
GC.start
# memory usage drops a relatively small amount, from 1.6 GB to 1.39
我正在用python写一个端口扫描程序,一切正常,但我想实现crtl+c中断函数来终止程序,它会停止主程序,但仍有线程在运行。如何使用ctrl+c键完全终止程序?
class StatusChecker(threading.Thread):
"""
The thread that will check HTTP statuses.
"""
#: The queue of urls
url_queue = None
#: The queue our results will go into
Python多处理池在Linux和Windows之间有不同的行为。
当按工作人员的数量运行方法时,在Linux中它运行的是作为参数给定的特定函数的作用域上的进程,但是在Windows中,每个工作人员在父进程的范围内运行,并再次使用它不应该使用的代码。
例如:(只用于使其与我的代码类似)
from multiprocessing import Pool, Event
from flask import Flask
print(">>> This code running for every each worker")
app = Flask(__name__