Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid cpu hogging #9

Closed
KilianB opened this issue Apr 29, 2019 · 1 comment
Closed

Avoid cpu hogging #9

KilianB opened this issue Apr 29, 2019 · 1 comment

Comments

@KilianB
Copy link

KilianB commented Apr 29, 2019

In your last commit (49469f8) you might have missed this loop

https://github.com/xXAligatorXx/RepostCheckerBot/blob/d43b314d874f78e695f49b7c4f5b7e4063cc6a2c/database.py#L250-L266

The applied fix to add a sleep will solve the immediate issue. The proper way to handle tasks is to use a task/event scheduler (https://docs.python.org/3/library/sched.html#). If you want to repeatedly run them make sure the task reschedules itself. This way you have more control over, can cancel it at any time, and still execute it even if an exception is thrown in the function.

A second improvement you can implement, if you want t really clean code, do not run the delete task in a fixed delay loop but rather just as necessary. You can retrieve the oldest/newest time in the sql query and compute the next time a deletion operation is necessary and schedule the appropriate task right away.

https://github.com/xXAligatorXx/RepostCheckerBot/blob/d43b314d874f78e695f49b7c4f5b7e4063cc6a2c/app.py#L43

@A1igator
Copy link
Owner

A1igator commented Jun 8, 2019

fixed

@A1igator A1igator closed this as completed Jun 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants