exit ''' from multiprocessing import Process, Queue import os, time, random def write(q): print('Process to write: %s' % os.getpid()) for value in ['A', 'B', 'C']: print('Put %s to queue...' % value) q.put(value) time.sleep(random.random()) def read(q): print('Process to read: %s' % os.getpid()) while True: value = q.get(True) print('Get %s from queue.' % value) if __name__ == '__main__': q = Queue() pw = Process(target=write, args=(q, )) pr = Process(target=read, args=(q, )) pw.start() pr.start() pw.joiin() pr.terminate()
GPIO.setup(button2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(button3, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) ID='bf8057981097462a95729337360b7f03' SECRET='264737bc4ad443429635d93babefc597' URI='https://localhost/' scope = 'user-read-playback-state user-modify-playback-state' token = util.prompt_for_user_token(username='******', scope=scope,client_id=ID,client_secret=SECRET, redirect_uri=URI) #init of player and classes sp = spotipy.Spotify(auth=token) reader = Reader(sp) playback = PlaybackModifier(sp) try: reader.update_LCD() while True: p = Process(target=readerThread) q = Process(target=scanThread) q.start() p.start() p.join() q.joiin() except KeyboardInterrupt: GPIO.cleanup() finally: GPIO.cleanup()