Repository: MLH-Fellowship/pearpy (language: python)

Issue:
Create `add_thread` and `remove_thread functions`
Make functions to add and remove threads to/from thread pool


Discussion / hints:

Fix patch:
diff --git a/.gitignore b/.gitignore
index 2eea525..dd8dae2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,1 +1,3 @@
-.env
\ No newline at end of file
+.env
+
+/pear/__pycache__
\ No newline at end of file
diff --git a/pear/pear.py b/pear/pear.py
index 5755b15..45d5aaa 100644
--- a/pear/pear.py
+++ b/pear/pear.py
@@ -1,15 +1,36 @@
-import threading
+from pear_thread import PearThread
 
 class Pear():
-    def __init__(self, num_threads=0):
-        self.num_threads = num_threads
-        self.threads = []
+    def __init__(self):
+        self.threads = set([])
     
     def __check_race_conditions__(self):
         return False
 
+    def __get_thread_by_id__(self, id):
+        for thread in self.threads:
+            if id is thread.get_id():
+                return thread
+
+    def get_threads(self):
+        return self.threads
+
+    def get_thread_names(self):
+        return [thread.getName() for thread in self.threads]
+
+    def get_thread_ids(self):
+        return [thread.get_id() for thread in self.threads]
+
     def add_thread(self, func, args):
-        self.threads.append(threading.Thread(target=func, args=(args)))
+        t = PearThread(func, args)
+        t.setName(func.__name__ + '(' + str(args) + ')')
+        self.threads.add(t)
+
+    def remove_thread(self, id):
+        for thread in self.threads:
+            if id is thread.get_id():
+                self.threads.remove(self.__get_thread_by_id__(id))
+                return
 
     def run(self):
         for thread in self.threads:
diff --git a/pear/pear_thread.py b/pear/pear_thread.py
new file mode 100644
index 0000000..db66c02
--- /dev/null
+++ b/pear/pear_thread.py
@@ -0,0 +1,10 @@
+import threading
+import uuid
+
+class PearThread(threading.Thread):
+    def __init__(self, func, args):
+        super().__init__(target=func, args=(args if (type(args) is list) else [args]))
+        self.id = uuid.uuid4().int & (1<<16)-1
+
+    def get_id(self):
+        return self.id
\ No newline at end of file


Test patch:
diff --git a/pear/test_pear.py b/pear/test_pear.py
new file mode 100644
index 0000000..e594b15
--- /dev/null
+++ b/pear/test_pear.py
@@ -0,0 +1,14 @@
+from pear import Pear
+
+def t1(num1, num2):
+    print('t1: ', num1 + num2)
+
+def t2(num):
+    print('t2: ', num) 
+
+pear = Pear()
+pear.add_thread(t1, [4, 5])
+pear.add_thread(t2, 4)
+print(pear.get_threads())
+pear.remove_thread(pear.get_thread_ids()[0])
+print(pear.get_threads())
\ No newline at end of file