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

Issue:
Setup module file structure
 - Set up file structure for pear module
 - Use poetry for package management
Created pear and pear thread classes
Created Pear and PearThread classes with full functionalities

closes #2 


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/README.md b/README.md
index 84f5f27..b856b28 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,27 @@
-# Pre Fellowship Template
+# Pear
+The Python package for (pear)allelizing your tasks across multiple CPU threads.
 
-This is a template to help you get started with your projects. Find out more information inside of the Fellow Handbook.
+## Usage
+ 1. Create a `Pear()` object. This will be a wrapper for all of your multithreaded processes.
+ 2. Identify the functions on which you would like to paralleilze computation.
+ 3. Add your tasks to the Pear object. If a potential race condition is detected, an error will be thrown.
+ 4. Run the paraellelized processes.
 
-This template has a `main` and `staging` branch already setup. 
+## Example
+```
+from pear import Pear
 
-- Code will only be merged into `main` once your Pod Leader has reviewed your code. At the end of each week, there will be a code freeze. Your Pod Leader will review it before it's merged.
-- During the week, you'll merge code into `staging`. 
+# First function to be parallelized
+def t1(num1, num2):
+    print('t1: ', num1 + num2)
+    
+# Second function to be paralellized
+def t2(num):
+    print('t2: ', num) 
+
+# Create pear object, add threads, and run
+pear = Pear()
+pear.add_thread(t1, [4, 5])
+pear.add_thread(t2, 4)
+pear.run()
+```
diff --git a/pear/__init__.py b/pear/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/pear/pear.py b/pear/pear.py
new file mode 100644
index 0000000..45d5aaa
--- /dev/null
+++ b/pear/pear.py
@@ -0,0 +1,39 @@
+from pear_thread import PearThread
+
+class Pear():
+    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):
+        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:
+            thread.start()
+        for thread in self.threads:
+            thread.join()
\ No newline at end of file
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
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..707de39
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,15 @@
+[tool.poetry]
+name = "pear"
+version = "0.1.0"
+description = ""
+authors = ["aidenszeto <aszeto35@gmail.com>"]
+license = "MIT"
+
+[tool.poetry.dependencies]
+python = "^3.8"
+
+[tool.poetry.dev-dependencies]
+
+[build-system]
+requires = ["poetry-core>=1.0.0"]
+build-backend = "poetry.core.masonry.api"


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