There are so many issues in this code, I am shocked!
First of all, the LICENSE
file states out that the given project is licensed under the
GNU General Public License v3.0 while the readme.md
says it is licensed under
the MIT license?
Now, the code itself is full of issues:
-
PEP8
: The code clearly breaks the style convention specified by PEP8
- inline imports of multiple packages
- unused import
multiprocessing
- missing 2 empty lines between functions and classes
- wrong type annotations
- inconvenient use of type annotations
- raw
except
clause
- and so on
-
threading.Lock
is completely misused
def printer(self, color, status, code):
threading.Lock().acquire()
print(f"{color} {status} > {Fore.RESET}discord.gift/{code}")
This code is not thread safe as the Lock
is created within that method, which means that different threads will create
different Lock
instances, making this line of code completely useless. Better would be:
# global variable
lock = threading.Lock()
def safe_print() -> None:
with lock:
print("hi")
- What is that?
"".join(random.choice("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890") for _ in range(16))
rewrite as:
from string import ascii_letters, digits
import random
"".join(random.choices(ascii_letters + digits, k=16))
-
Files are opened explicitly with the r
parameter although it is the default parameter value
open("blah", "r")
== open("blah")
-
Why so much work?
def proxies_count(self):
proxies_list = 0
with open('config/proxies.txt', 'r') as file:
proxies = [line.strip() for line in file]
for _ in proxies:
proxies_list += 1
return int(proxies_list)
# Is the same as
def proxy_count(self) -> int:
with open("config/proxies.txt") as file:
return len(file.readlines())
- Only one thread is running (always one!!!):
threading.Thread(target=DNG.run(), args=()).start()
look at target
! You are calling run
instead of passing the method itself to target
. That means that you execute the method in the current thread instead of the new thread that you are trying to create there, essentially blocking the while
loop and hence blocking the creation of new threads.