相关疑难解决方法(0)

多处理与线程Python

我试图了解多处理优于线程的优势.我知道多处理可以解决Global Interpreter Lock问题,但是还有什么其他优点,并且线程不能做同样的事情?

python multithreading multiprocessing

739
推荐指数
10
解决办法
32万
查看次数

Cython 并行 prange - 线程局部性?

我正在使用 prange 迭代这样的列表:

from cython.parallel import  prange, threadid

cdef int tid
cdef CythonElement tEl
cdef int a, b, c

# elList: python list of CythonElement instances is passed via function call
for n in prange(nElements, schedule='dynamic', nogil=True):
    with gil:
        tEl = elList[n]
        tid =  threadid()
        a = tEl.a
        b = tEl.b
        c = tEl.c 

        print("thread {:} elnumber {:}".format(tid, tEl.elNumber))

   #nothing is done here

    with gil:
        print("thread {:} elnumber {:}".format(tid, tEl.elNumber))

    # some other computations based on a, b and c …
Run Code Online (Sandbox Code Playgroud)

parallel-processing multithreading cython

4
推荐指数
1
解决办法
2305
查看次数