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 type (my variable is a letter), and where to put my variable's name ?
EDIT
I tried using the Manager to share my letter between processes. But the only thing I have now is Value('ctypes.c_char_p', '
(The key you hit here)')
printed in the Python Shell and still no sound.
The console also seems a bit slower than usual when using the manager. There's an almost one second delay between the time I hit the key and when the Value
appears on screen.
My code now looks like this :
#Import
from tkinter import *
import wave
import winsound
import multiprocessing
#Functions
def key(event):
temp = event.char
manager = multiprocessing.Manager()
manager.Value(ctypes.c_char_p, temp)
hitkey = manager.Value(ctypes.c_char_p, temp)
instance = multiprocessing.Process(target=player, args=(hitkey,))
instance.start()
def player(hitkey):
print(hitkey + "1")
winsound.PlaySound(hitkey + '.wav', winsound.SND_FILENAME|winsound.SND_NOWAIT|winsound.SND_ASYNC)
if __name__ == "__main__":
#Initialisation
fenetre = Tk()
frame = Frame(fenetre, width=200, height=100)
#TK
frame.focus_set()
frame.bind("<Key>", key)
frame.pack()
fenetre.mainloop()