From e7e453a5f6d205c7e45d11a8fd71d5b61c26bec0 Mon Sep 17 00:00:00 2001 From: Ben Shealy Date: Sun, 9 Aug 2020 13:07:34 -0400 Subject: [PATCH] Replaced multithreading with multiprocessing --- app/meter.py | 4 ++-- app/player_madao.py | 4 ++-- app/player_vlc.py | 4 ++-- app/za_studio.py | 9 +++------ test/test_meter.py | 4 ++-- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/meter.py b/app/meter.py index 2ab9d27..909502c 100644 --- a/app/meter.py +++ b/app/meter.py @@ -1,5 +1,5 @@ """The meter module provides the Meter class.""" -import thread +import multiprocessing as mp import time import Tkinter from Tkinter import Canvas @@ -104,7 +104,7 @@ def _run(self): def start(self): """Start the meter.""" self._is_playing = True - thread.start_new_thread(self._run, ()) + mp.Process(target=self._run).start() def reset(self): """Reset the meter.""" diff --git a/app/player_madao.py b/app/player_madao.py index 7096510..c636b14 100755 --- a/app/player_madao.py +++ b/app/player_madao.py @@ -3,7 +3,7 @@ This implementation of Player uses python wrappers for libmad and libao, which provide interfaces to audio files and audio devices. """ -import thread +import multiprocessing as mp import time import ao import mad @@ -67,7 +67,7 @@ def play(self, callback=None): self._is_playing = True self._callback = callback - thread.start_new_thread(self._play_internal, ()) + mp.Process(target=self._play_internal).start() def stop(self): """Stop the audio stream.""" diff --git a/app/player_vlc.py b/app/player_vlc.py index 51c647f..191963a 100755 --- a/app/player_vlc.py +++ b/app/player_vlc.py @@ -4,10 +4,10 @@ it also uses libmad to retreive the length of the file. This implementation seems to work, although it prints cryptic messages from time to time. """ +import multiprocessing as mp import os import signal import subprocess -import thread import time import mad @@ -68,7 +68,7 @@ def play(self, callback=None): self._pid = subprocess.Popen(self._command).pid self._is_playing = True self._callback = callback - thread.start_new_thread(self._play_internal, ()) + mp.Process(target=self._play_internal).start() def stop(self): """Stop the audio stream.""" diff --git a/app/za_studio.py b/app/za_studio.py index d1543e1..ffe9466 100755 --- a/app/za_studio.py +++ b/app/za_studio.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """The Studio module provides a GUI for the digital library.""" -import thread +import multiprocessing as mp import Tkinter from Tkinter import Frame, Label, BooleanVar, Checkbutton, Entry, Button import database @@ -124,11 +124,8 @@ def _search_internal(self): print "Found %d results." % len(self._search_results) def search(self, *args): - """Search the digital library. - - :param args - """ - thread.start_new_thread(self._search_internal, ()) + """Search the digital library.""" + mp.Process(target=self._search_internal).start() def select_cart(self, index): """Select a cart from the search results. diff --git a/test/test_meter.py b/test/test_meter.py index f490f81..bcda7d9 100755 --- a/test/test_meter.py +++ b/test/test_meter.py @@ -1,9 +1,9 @@ #!/usr/bin/env python """Test suite for the meter module.""" +import multiprocessing as mp import sys import time -import thread from Tkinter import Frame, Canvas sys.path.insert(0, 'app') @@ -33,7 +33,7 @@ def __init__(self): Canvas(self.master, width=900, height=100, bg='#00F').grid(row=2, column=0, columnspan=NUM_COLS) self._meter.start() - thread.start_new_thread(self._run, ()) + mp.Process(target=self._run).start() self.master.title("Testing Program") self.master.mainloop()