2 years ago

#68000

test-img

N3RDIUM

Cython: call Python function from inside prange()

The problem

I am trying to implement a threaded chunk manager for my game. But it gives the error:

f:\PyCraft\helpers\terrain_generator_helper.pyx:6:12: target may not be a Python object as we don't have the GIL

I am new to cython, so expect bugs in my code. I am on windows 10.

The code

import random
from cython.parallel import  prange

cdef func_exec(func):
    with nogil:
        for n in prange(0, 1):
            with gil:
                func()

def _start_generaion(world):
    random_index = world._queue[random.randint(0, len(world._queue) - 1)]
    world.all_chunks[random_index].generate()
    world._queue.remove(random_index)

def start_generaion(world):
    func_exec(lambda: _start_generaion(world))

Thanks in advance!

python

multithreading

cython

gil

0 Answers

Your Answer

Accepted video resources