Current state of using multiprocess in bge?

One of those threads again…

Any ideas if it can be done or should I move to network sockets right away?
Currently it seems to open new new instances of blender or error.

First problems seems that there is no pythonw.exe in blender 2.77/python.
Well, manually referencing (set_executable) my own installation python seems let it pass that.

Second, that I can’t get the communication going. Either the threads don’t start or they just sit idle without picking task from the queue.

What to try:
https://blenderartists.org/forum/showthread.php?348061-Simple-Multiprocessing-Demo
adding ‘set_executable(‘C:\Users\YOUR_USER\AppData\Local\Programs\Python\Python35-32\pythonw.exe’)’

or always->pythonModule threadTest.main


from multiprocessing import Process,JoinableQueue,Queue,cpu_count,set_executable
from time import time,sleep


class Consumer(Process):
    
    def __init__(self, task_queue, result_queue):
        Process.__init__(self)
        self.task_queue = task_queue
        self.result_queue = result_queue


    def run(self):
        proc_name = self.name
        while True:
            next_task = self.task_queue.get()
            if next_task is None:
                # Poison pill means shutdown
                print( '%s: Exiting' % proc_name)
                self.task_queue.task_done()
                break
            answer = next_task()
            self.task_queue.task_done()
            self.result_queue.put(answer)
        return




class Task(object):
    def __init__(self,index):
        self.index  = index
    def __call__(self):
        a, b = 0, 1
        for i in range(10000+self.index):       
            a, b = b, a+b
        return b%1000






def main():
    set_executable('C:\\Users\\Fred\\AppData\\Local\\Programs\\Python\\Python35-32\\pythonw.exe')


    # Establish communication queues
    tasks = JoinableQueue()
    results = Queue()
    
    # Start consumers
    num_consumers = cpu_count() 
    print( 'Creating %d consumers' % num_consumers)
    consumers = [ Consumer(tasks, results) for i in range(num_consumers) ]
    for w in consumers:
        w.start()
    
    # Enqueue jobs
    num_jobs = 3000
    for i in range(num_jobs):
        tasks.put(Task(i))
    
    # Add a poison pill for each consumer
    for i in range(num_consumers):
        tasks.put(None)
    #tasks.join()
    #input()
    


if __name__ == '__main__':
    main()



I didn’t have any luck with this in the past, and it seems like it would work differently on different computers or different systems.
I can’t think of a situation where a slight improvement in processing speed would outweigh the very real problems that could crop up from people not being able to run the game.

Worst case Blender tried to open infinite recursive versions of itself and crashed to the blue screen of death. I don’t think anyone would want to play my game after that happened to their computer.

Other problems, some people install games in the program files folder, there could be restrictions on permissions which stop your game from running.

I found threading would do what I needed, i.e. run a process in the background so blender doesn’t lock up.