From d611889d7651c988ee51b3e3cbc493b25612a5ea Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 13 Mar 2022 11:01:07 +0000 Subject: [PATCH] Debug for thread events --- daemon.py | 33 +++++++++++++++++++-------------- inbox.py | 3 ++- manualapprove.py | 2 ++ newsdaemon.py | 3 ++- posts.py | 4 ++++ schedule.py | 3 ++- shares.py | 3 ++- threads.py | 1 + 8 files changed, 34 insertions(+), 18 deletions(-) diff --git a/daemon.py b/daemon.py index 60e845781..c84a0c7cd 100644 --- a/daemon.py +++ b/daemon.py @@ -1605,6 +1605,7 @@ class PubServer(BaseHTTPRequestHandler): print('Creating outbox thread ' + account_outbox_thread_name + '/' + str(self.server.outbox_thread_index[account_outbox_thread_name])) + print('THREAD: _post_to_outbox') self.server.outboxThread[account_outbox_thread_name][index] = \ thread_with_trace(target=self._post_to_outbox, args=(message_json.copy(), @@ -20184,7 +20185,7 @@ def run_shares_expire(version_number: str, base_dir: str) -> None: def run_posts_watchdog(project_version: str, httpd) -> None: """This tries to keep the posts thread running even if it dies """ - print('Starting posts queue watchdog') + print('THREAD: Starting posts queue watchdog') posts_queue_original = httpd.thrPostsQueue.clone(run_posts_queue) httpd.thrPostsQueue.start() while True: @@ -20192,6 +20193,7 @@ def run_posts_watchdog(project_version: str, httpd) -> None: if httpd.thrPostsQueue.is_alive(): continue httpd.thrPostsQueue.kill() + print('THREAD: restarting posts queue') httpd.thrPostsQueue = posts_queue_original.clone(run_posts_queue) httpd.thrPostsQueue.start() print('Restarting posts queue...') @@ -20200,7 +20202,7 @@ def run_posts_watchdog(project_version: str, httpd) -> None: def run_shares_expire_watchdog(project_version: str, httpd) -> None: """This tries to keep the shares expiry thread running even if it dies """ - print('Starting shares expiry watchdog') + print('THREAD: Starting shares expiry watchdog') shares_expire_original = httpd.thrSharesExpire.clone(run_shares_expire) httpd.thrSharesExpire.start() while True: @@ -20208,6 +20210,7 @@ def run_shares_expire_watchdog(project_version: str, httpd) -> None: if httpd.thrSharesExpire.is_alive(): continue httpd.thrSharesExpire.kill() + print('THREAD: restarting shares watchdog') httpd.thrSharesExpire = shares_expire_original.clone(run_shares_expire) httpd.thrSharesExpire.start() print('Restarting shares expiry...') @@ -20688,13 +20691,13 @@ def run_daemon(crawlers_allowed: [], print('Creating shared item files directory') os.mkdir(base_dir + '/sharefiles') - print('Creating fitness thread') + print('THREAD: Creating fitness thread') httpd.thrFitness = \ thread_with_trace(target=fitness_thread, args=(base_dir, httpd.fitness), daemon=True) httpd.thrFitness.start() - print('Creating cache expiry thread') + print('THREAD: Creating cache expiry thread') httpd.thrCache = \ thread_with_trace(target=expire_cache, args=(base_dir, httpd.person_cache, @@ -20706,12 +20709,13 @@ def run_daemon(crawlers_allowed: [], # number of mins after which sending posts or updates will expire httpd.send_threads_timeout_mins = send_threads_timeout_mins - print('Creating posts queue') + print('THREAD: Creating posts queue') httpd.thrPostsQueue = \ thread_with_trace(target=run_posts_queue, args=(base_dir, httpd.send_threads, debug, httpd.send_threads_timeout_mins), daemon=True) if not unit_test: + print('THREAD: run_posts_watchdog') httpd.thrPostsWatchdog = \ thread_with_trace(target=run_posts_watchdog, args=(project_version, httpd), daemon=True) @@ -20719,11 +20723,12 @@ def run_daemon(crawlers_allowed: [], else: httpd.thrPostsQueue.start() - print('Creating expire thread for shared items') + print('THREAD: Creating expire thread for shared items') httpd.thrSharesExpire = \ thread_with_trace(target=run_shares_expire, args=(project_version, base_dir), daemon=True) if not unit_test: + print('THREAD: run_shares_expire_watchdog') httpd.thrSharesExpireWatchdog = \ thread_with_trace(target=run_shares_expire_watchdog, args=(project_version, httpd), daemon=True) @@ -20752,7 +20757,7 @@ def run_daemon(crawlers_allowed: [], create_initial_last_seen(base_dir, http_prefix) - print('Creating inbox queue') + print('THREAD: Creating inbox queue') httpd.thrInboxQueue = \ thread_with_trace(target=run_inbox_queue, args=(httpd.recent_posts_cache, @@ -20784,19 +20789,19 @@ def run_daemon(crawlers_allowed: [], httpd.default_reply_interval_hrs, httpd.cw_lists), daemon=True) - print('Creating scheduled post thread') + print('THREAD: Creating scheduled post thread') httpd.thrPostSchedule = \ thread_with_trace(target=run_post_schedule, args=(base_dir, httpd, 20), daemon=True) - print('Creating newswire thread') + print('THREAD: Creating newswire thread') httpd.thrNewswireDaemon = \ thread_with_trace(target=run_newswire_daemon, args=(base_dir, httpd, http_prefix, domain, port, httpd.translate), daemon=True) - print('Creating federated shares thread') + print('THREAD: Creating federated shares thread') httpd.thrFederatedSharesDaemon = \ thread_with_trace(target=run_federated_shares_daemon, args=(base_dir, httpd, @@ -20818,25 +20823,25 @@ def run_daemon(crawlers_allowed: [], httpd.signing_priv_key_pem = get_instance_actor_key(base_dir, domain) if not unit_test: - print('Creating inbox queue watchdog') + print('THREAD: Creating inbox queue watchdog') httpd.thrWatchdog = \ thread_with_trace(target=run_inbox_queue_watchdog, args=(project_version, httpd), daemon=True) httpd.thrWatchdog.start() - print('Creating scheduled post watchdog') + print('THREAD: Creating scheduled post watchdog') httpd.thrWatchdogSchedule = \ thread_with_trace(target=run_post_schedule_watchdog, args=(project_version, httpd), daemon=True) httpd.thrWatchdogSchedule.start() - print('Creating newswire watchdog') + print('THREAD: Creating newswire watchdog') httpd.thrNewswireWatchdog = \ thread_with_trace(target=run_newswire_watchdog, args=(project_version, httpd), daemon=True) httpd.thrNewswireWatchdog.start() - print('Creating federated shares watchdog') + print('THREAD: Creating federated shares watchdog') httpd.thrFederatedSharesWatchdog = \ thread_with_trace(target=run_federated_shares_watchdog, args=(project_version, httpd), daemon=True) diff --git a/inbox.py b/inbox.py index 1f83888e7..cbe5dbe16 100644 --- a/inbox.py +++ b/inbox.py @@ -3747,7 +3747,7 @@ def _restore_queue_items(base_dir: str, queue: []) -> None: def run_inbox_queue_watchdog(project_version: str, httpd) -> None: """This tries to keep the inbox thread running even if it dies """ - print('Starting inbox queue watchdog') + print('THREAD: Starting inbox queue watchdog') inbox_queue_original = httpd.thrInboxQueue.clone(run_inbox_queue) httpd.thrInboxQueue.start() while True: @@ -3755,6 +3755,7 @@ def run_inbox_queue_watchdog(project_version: str, httpd) -> None: if not httpd.thrInboxQueue.is_alive() or httpd.restart_inbox_queue: httpd.restart_inbox_queue_in_progress = True httpd.thrInboxQueue.kill() + print('THREAD: restarting inbox queue watchdog') httpd.thrInboxQueue = inbox_queue_original.clone(run_inbox_queue) httpd.inbox_queue.clear() httpd.thrInboxQueue.start() diff --git a/manualapprove.py b/manualapprove.py index df7c7708b..8036b8cf7 100644 --- a/manualapprove.py +++ b/manualapprove.py @@ -88,6 +88,7 @@ def manual_deny_follow_request_thread(session, session_onion, session_i2p, """Manually deny a follow request, within a thread so that the user interface doesn't lag """ + print('THREAD: manual_deny_follow_request') thr = \ thread_with_trace(target=manual_deny_follow_request, args=(session, session_onion, session_i2p, @@ -321,6 +322,7 @@ def manual_approve_follow_request_thread(session, session_onion, session_i2p, """Manually approve a follow request, in a thread so as not to cause the UI to lag """ + print('THREAD: manual_approve_follow_request') thr = \ thread_with_trace(target=manual_approve_follow_request, args=(session, session_onion, session_i2p, diff --git a/newsdaemon.py b/newsdaemon.py index e47725b7e..4d3209f6f 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -882,7 +882,7 @@ def run_newswire_daemon(base_dir: str, httpd, def run_newswire_watchdog(project_version: str, httpd) -> None: """This tries to keep the newswire update thread running even if it dies """ - print('Starting newswire watchdog') + print('THREAD: Starting newswire watchdog') newswire_original = \ httpd.thrPostSchedule.clone(run_newswire_daemon) httpd.thrNewswireDaemon.start() @@ -891,6 +891,7 @@ def run_newswire_watchdog(project_version: str, httpd) -> None: if httpd.thrNewswireDaemon.is_alive(): continue httpd.thrNewswireDaemon.kill() + print('THREAD: restarting newswire watchdog') httpd.thrNewswireDaemon = \ newswire_original.clone(run_newswire_daemon) httpd.thrNewswireDaemon.start() diff --git a/posts.py b/posts.py index c5a15ea24..8ea445c55 100644 --- a/posts.py +++ b/posts.py @@ -2494,6 +2494,7 @@ def send_post(signing_priv_key_pem: str, project_version: str, send_threads[0].kill() send_threads.pop(0) print('WARN: thread killed') + print('THREAD: thread_send_post') thr = \ thread_with_trace(target=thread_send_post, args=(session, @@ -2881,6 +2882,7 @@ def send_signed_json(post_json_object: {}, session, base_dir: str, print('DEBUG: starting thread to send post') pprint(post_json_object) domain_full = get_full_domain(domain, port) + print('THREAD: thread_send_post 2') thr = \ thread_with_trace(target=thread_send_post, args=(session, @@ -3154,6 +3156,7 @@ def send_to_named_addresses_thread(session, session_onion, session_i2p, signing_priv_key_pem: str): """Returns a thread used to send a post to named addresses """ + print('THREAD: _send_to_named_addresses') send_thread = \ thread_with_trace(target=_send_to_named_addresses, args=(session, session_onion, session_i2p, @@ -3412,6 +3415,7 @@ def send_to_followers_thread(session, session_onion, session_i2p, signing_priv_key_pem: str): """Returns a thread used to send a post to followers """ + print('THREAD: send_to_followers') send_thread = \ thread_with_trace(target=send_to_followers, args=(session, session_onion, session_i2p, diff --git a/schedule.py b/schedule.py index 46e9b1a19..025a0f02e 100644 --- a/schedule.py +++ b/schedule.py @@ -193,7 +193,7 @@ def run_post_schedule(base_dir: str, httpd, max_scheduled_posts: int): def run_post_schedule_watchdog(project_version: str, httpd) -> None: """This tries to keep the scheduled post thread running even if it dies """ - print('Starting scheduled post watchdog') + print('THREAD: Starting scheduled post watchdog') post_schedule_original = \ httpd.thrPostSchedule.clone(run_post_schedule) httpd.thrPostSchedule.start() @@ -202,6 +202,7 @@ def run_post_schedule_watchdog(project_version: str, httpd) -> None: if httpd.thrPostSchedule.is_alive(): continue httpd.thrPostSchedule.kill() + print('THREAD: restarting scheduled post watchdog') httpd.thrPostSchedule = \ post_schedule_original.clone(run_post_schedule) httpd.thrPostSchedule.start() diff --git a/shares.py b/shares.py index bbca66365..af73be24d 100644 --- a/shares.py +++ b/shares.py @@ -1610,7 +1610,7 @@ def run_federated_shares_watchdog(project_version: str, httpd) -> None: """This tries to keep the federated shares update thread running even if it dies """ - print('Starting federated shares watchdog') + print('THREAD: Starting federated shares watchdog') federated_shares_original = \ httpd.thrPostSchedule.clone(run_federated_shares_daemon) httpd.thrFederatedSharesDaemon.start() @@ -1619,6 +1619,7 @@ def run_federated_shares_watchdog(project_version: str, httpd) -> None: if httpd.thrFederatedSharesDaemon.is_alive(): continue httpd.thrFederatedSharesDaemon.kill() + print('THREAD: restarting federated shares watchdog') httpd.thrFederatedSharesDaemon = \ federated_shares_original.clone(run_federated_shares_daemon) httpd.thrFederatedSharesDaemon.start() diff --git a/threads.py b/threads.py index 0aca29b25..c17ad025e 100644 --- a/threads.py +++ b/threads.py @@ -75,6 +75,7 @@ class thread_with_trace(threading.Thread): def clone(self, func): """Create a clone """ + print('THREAD: clone') return thread_with_trace(target=func, args=self._args, daemon=True)