相关疑难解决方法(0)

Linux中的线程与进程

我最近听过一些人说在Linux中,使用进程而不是线程几乎总是更好,因为Linux在处理进程方面非常有效,并且因为线程有很多问题(例如锁定).但是,我很怀疑,因为在某些情况下,线程似乎可以带来相当大的性能提升.

所以我的问题是,当遇到线程和进程都能很好地处理的情况时,我应该使用进程还是线程?例如,如果我正在编写Web服务器,我应该使用进程或线程(或组合)吗?

linux performance multithreading process

244
推荐指数
9
解决办法
11万
查看次数

Python线程不会同时运行

我是多线程处理的新手,所以如果我屠宰条款或遗漏一些明显的东西,请原谅我.

下面的代码不会提供任何时间优势,而不是相继调用相同的两个函数的不同代码.


import time
import threading

start_time = time.clock()

def fibonacci(nth): #can be ignored
    first = 0
    second = 1
    for i in range(nth):
        third = first + second
        first = second
        second = third
    print "Fibonacci number", i + 1, "is", len(str(first)), "digits long"

def collatz(collatz_max): #can be ignored
    for n in range(collatz_max):
        n = n + 1 #avoid entering 0
        solution = []
        solution.append(n)
        while n != 1:
            if n % 2 == 0:
                n = n / …
Run Code Online (Sandbox Code Playgroud)

python multithreading

5
推荐指数
1
解决办法
1717
查看次数

标签 统计

multithreading ×2

linux ×1

performance ×1

process ×1

python ×1