phase 2: code cleanup and simplification
All checks were successful
CI / syntax-check (push) Successful in 3s
CI / memory-leak-check (push) Successful in 11s

- Remove unused result_queue from WorkerThread and worker mode
- Remove num_targets abstraction, simplify to single-target mode
- Add _db_context() context manager for database connections
- Refactor 5 call sites to use context manager (finish, init, cleanup_stale, periodic saves)
- Mark _prep_db/_close_db as deprecated
- Add __version__ = '2.0.0' to ppf.py
- Add thread spawn stagger (0-100ms) in worker mode for Tor-friendly startup
This commit is contained in:
Username
2025-12-28 14:31:37 +01:00
parent 72a2dcdaf4
commit d219cc567f
2 changed files with 54 additions and 61 deletions

5
ppf.py
View File

@@ -1,5 +1,7 @@
#!/usr/bin/env python2
__version__ = '2.0.0'
import sys
import os
@@ -481,13 +483,12 @@ def worker_main(config):
# Create shared queues for worker threads
job_queue = proxywatchd.PriorityJobQueue()
result_queue = Queue.Queue()
completion_queue = Queue.Queue()
# Spawn worker threads with stagger to avoid overwhelming Tor
threads = []
for i in range(num_threads):
wt = proxywatchd.WorkerThread('w%d' % i, job_queue, result_queue)
wt = proxywatchd.WorkerThread('w%d' % i, job_queue)
wt.start_thread()
threads.append(wt)
time.sleep(random.random() / 10) # 0-100ms stagger per thread