mirror of
https://github.com/misiektoja/instagram_monitor.git
synced 2026-04-25 22:35:49 +03:00
[GH-ISSUE #52] Progress bar issue #38
Labels
No labels
Stale
Stale
bug
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/instagram_monitor#38
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @tomballgithub on GitHub (Jan 24, 2026).
Original GitHub issue: https://github.com/misiektoja/instagram_monitor/issues/52
Corner case, but wanted to share it, because I share a fix that might fix all cases.
Running in console mode with web interface. Clicked "send test webhook" and saw this in the console. It's the same issue where you cannot print during progress bar updates. And later a timestamp was added on top of the progress bar, so I updated what I pasted here
The tqdm progress bar has a tqdm.write() mechanism that can be used instead of print().
Maybe that should be used for a case like this (or all cases) where you need to print during an active progress bar
Example code from tqdm site:
Output looks like (it's not shown on the site), and those "Done task" writes are occurring during the progress bar.
It does a print to screen and then pushes progress bar to the next line:
@tomballgithub commented on GitHub (Jan 24, 2026):
I wasn't using the latest code, I need to test 3.0
@tomballgithub commented on GitHub (Jan 25, 2026):
I verified this still happened with 3.0 (scroll to the right in the sample below).
A few moments after the webhook check, the timestamp also gets written.
I think all that would be fine if the tdm.write() method is used per above, maybe in logger.write()?
@tomballgithub commented on GitHub (Jan 25, 2026):
I changed these prints to tqdm.write's and it didn't change the behavior:
Output:
@misiektoja commented on GitHub (Jan 25, 2026):
The tqdm.write() didn't work as it is a thread context mismatch. The progress bar lives in the monitoring thread, while the webhook message originates from the Flask web dashboard thread. When tqdm.write() is called from the dashboard thread, it doesn't have the context of the active progress bar in the other thread, so it just appends to the current line instead of clearing it.
Honestly I do not see any good solution for that. We could implement some kind of global registry to track active progress bars across threads. However, this adds significant architectural complexity and requires passing user/thread context to every part of the app that might print (webhooks, emails, status logs).
We could also queue messages and wait for the progress bar to finish. But since it might take long time (~40 minutes in your case), the feedback would arrive too late to be useful.
We could also suppress the message completely, but then it is gone forever.
@tomballgithub commented on GitHub (Jan 25, 2026):
Don't all prints go through your logger routine? Is there a central way to do this there? Such as if there is an active progress bar, to turn the print into a tqdm.write vis the correct thread?
That said, it's definitely not worth rearchitecting anything. This progress bar went from simple to complex once multi account monitoring was added.
@misiektoja commented on GitHub (Jan 29, 2026):
Yes, the Logger class is indeed the central bottleneck for all output.
But the tricky part (even at the Logger level) is thread isolation. Since progress bars are stored in _thread_local state to support multi-target monitoring, the Logger (when called from the web dashboard thread) can't see the active progress bar owned by a monitoring thread.
To bridge that gap, we'd need to implement that global registry I mentioned earlier which is quite tricky.
Given how progress bars became significantly more complex with the move to multi-account support, I think your suggestion to leave it as is for now is the most pragmatic approach. It keeps the core logging logic simple and avoids introducing new global state management just for test notifications.
@tomballgithub commented on GitHub (Jan 29, 2026):
Corner case, not worth fixing...