# 无意中炸了我的电脑.. 为 python 计算我们的多处理

#### unintentionally fried my pc.. figuring our multiprocessing for python

``````    import time
def prime(x):
start = time.time()
num = x+1
range_num = []
two = x/2
five = x/5
ten = x/10
if not two.is_integer() or five.is_integer() or ten.is_integer():
for i in range(1, num):
y = x/i
if y.is_integer():
range_num.append(True)
else:
range_num.append(False)

total = 0
for ele in range(0, len(range_num)):
total = total + range_num[ele]
if num == 1:
print(1, " is a prime number")
elif total == 2:
print(num-1, " is a prime number")
else:
print(num-1, " is not a prime number")
else:
print(num - 1, " is not a prime number")
print("This took ", round((time.time() - start), 2), "Seconds to complete")

prime(269996535)
``````

``````    import time
import multiprocessing

global range_num
range_num = []

def part_one(x, denom):
if not denom == 0:
for i in range(1, x):
y = x/denom
if y.is_integer():
range_num.append(True)
else:
range_num.append(False)

if __name__ == '__main__':
start = time.time()
x = int(input("Enter number: "))
num = x+1
range_num = []
if num-1 == 1:
print("1 is a prime number")
for i in range(0, x):
p = multiprocessing.Process(target=part_one, args=(x, i,))
p.start()
for process in range_num:
process.join()

total = 0
for ele in range(0, len(range_num)):
total = total + range_num[ele]
if total == 2:
print(num-1, " is a prime number")
else:
print(num - 1, " is not a prime number")
``````
2 个回复

...我的程序开始一一崩溃，然后最终蓝屏。 有人可以解释为什么会这样吗...？

PS，如果您需要将裸露的内置硬盘驱动器连接到 PC，那么小型台式风扇是必不可少的。 它们不能在没有强制气流的情况下工作。

``````def has_divisors_in_range(number: int, the_range):
for divisor_candidate in the_range:
# If `divisor_candidate` divides `number` evenly,
# then `number` is not prime
if number % divisor_candidate == 0:
return divisor_candidate

return -1

nprocs = 4
processes = [
multiprocessing.Process(
target= has_divisors_in_range,
args=(num, range(t + 1, num + 1, nprocs))
)
for t in range(1, nprocs + 1)
]

# Wait for the processes somehow...
``````

1 python3多处理示例崩溃了我的电脑:(

2 为什么 Python 多处理无法在我的 PC 上运行？

4 如果我在同一台电脑上的不同虚拟机上运行带有多处理功能的 python 代码，GIL 会干扰吗？

2019-08-07 12:15:09 1 64   gil
5 PDO炸了我的网站-有什么提示吗？

2014-04-12 00:18:57 0 158   pdo
6 我炸过我的A2了吗？

2014-03-07 05:10:48 1 288   arduino
7 Python多处理会逐渐增加内存，直到它运行我们的

8 我可以使用 Spyder Windows PC 实现 Python 多处理，但为什么呢？

2021-07-07 01:35:51 1 28   spyder
9 我的“工具”的Python线程或多处理

10 解决如何在Tkinter中为我的Python程序更新标签的问题

2017-03-14 12:31:16 1 48   tkinter