multiprocessing.value clear syntax?

前端 未结 2 1449
無奈伤痛
無奈伤痛 2020-12-29 10:34

I want to use multiprocessing.Value to use a variable in multiple processes, but the syntax is not clear on Python\'s documentation. Can anyone tell me what should I use as

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-29 11:05

    I think the original issue you were having (causing the TypeError) was because the lock argument to the multiprocessing.Value constructor is a keyword-only argument. You need to call multiprocessing.Value("c", temp, lock=False) in order for it to do what you were wanting to do.

    However, I don't think you need to use a Value object at all. You're passing the keycode as an argument to your other process, and the Value isn't being used at all. I'd get rid of it completely:

    def key(event): 
       instance = multiprocessing.Process(target=player, args=(event.char,)) 
       instance.start()
    

提交回复
热议问题