]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - music_sampler.py
Fix threading problems with ipython
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler.py
index fd03009495f72cddfaa635558190d70badeb05ae..d4fc2a726ee6923772bfd36d782ca5ff0014fc9f 100644 (file)
@@ -27,6 +27,7 @@ contexts = [
 
 context = 'normal'
 
+#### Normal workflow ####
 while 1:
     event = pygame.event.wait()
 
@@ -35,7 +36,7 @@ while 1:
             event.mod  == 4160 and
             event.key  == pygame.K_c):
         for thread in threading.enumerate():
-            if thread is threading.current_thread():
+            if thread.getName()[0:2] != "MS":
                 continue
             thread.join()
 
@@ -46,13 +47,18 @@ while 1:
         if event.type == pygame.KEYDOWN:
             key = mapping.find_by_key_num(event.key)
             if key is not None:
-                threading.Thread(target=key.do_actions).start()
+                threading.Thread(name = "MSKeyAction", target=key.do_actions).start()
         elif event.type == pygame.MOUSEBUTTONUP:
             key = mapping.find_by_collidepoint(pygame.mouse.get_pos())
             if key is not None:
-                threading.Thread(target=key.list_actions, args = [screen]).start()
+                threading.Thread(name = "MSClic", target=key.list_actions, args = [screen]).start()
 
     draw_lock.acquire()
     pygame.display.flip()
     draw_lock.release()
 
+#### In Ipython ####
+# for thread in threading.enumerate():
+#     if thread.getName()[0:2] != "MS":
+#         continue
+#     thread.join()