Skip to content

Start additional threads only when necessary - #415

Merged
tsnoam merged 6 commits into
python-telegram-bot:masterfrom
wronglink:dont-start-threads-on-init
Sep 27, 2016
Merged

Start additional threads only when necessary#415
tsnoam merged 6 commits into
python-telegram-bot:masterfrom
wronglink:dont-start-threads-on-init

Conversation

@wronglink

Copy link
Copy Markdown
Contributor

I have several troubles with JobQueue and Dispatcher automatically start new threads during it's initialisation. I guess it's quite unexpected behaviour to have a branch of threads just by creating new Updater, without starting it. Instead of it, I propose the Updater instance should start all necessary threads on inside it's start methods: start_polling and start_webhook.

@jh0ker jh0ker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall a great PR, thank you very much!

I left some comments where I think you were missing something. Please await feedback by @tsnoam before taking any action. Feel free to respond to my comments though!

self.logger.error(msg)
raise TelegramError(msg)

self._init_async_threads(uuid4(), self.workers)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I agree with this change, but I'd like @tsnoam to give it a look as well.

Comment thread telegram/ext/jobqueue.py
@@ -51,10 +49,6 @@ def __init__(self, bot, prevent_autostart=False):
""":type: float"""
self._running = False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment thread telegram/ext/jobqueue.py Outdated
self.start()

def put(self, job, next_t=None):
"""Queue a new job. If the JobQueue is not running, it will be started.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring is wrong (and was wrong before your PR). The job queue is never started in this method. Please remove that sentence.

Comment thread telegram/ext/updater.py Outdated
self.running = True

# Create & start threads
self._init_thread(self.job_queue.start, "job_queue")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can simply call self.job_queue.start(), I believe. The method is already spawning a new thread.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 @jh0ker comment here.
@wronglink can you please fix?

Comment thread telegram/ext/updater.py Outdated
self.running = True

# Create & start threads
self._init_thread(self.job_queue.start, "job_queue")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment

@jh0ker

jh0ker commented Sep 23, 2016

Copy link
Copy Markdown
Member

Hey, thanks! I did a short code review. As mentioned in the review, I am hereby pinging @tsnoam to check out the code as well ;)

Edit: I'm putting this up for the 6.0 milestone because of the removal of the prevent_autostart kwarg. Perhaps we can ship it with 5.2 and get away with a deprecation warning ^^

@jh0ker jh0ker added enhancement 📋 pending-reply work status: pending-reply labels Sep 23, 2016
@jh0ker jh0ker added this to the 6.0 milestone Sep 23, 2016

@tsnoam tsnoam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wronglink
All in all looks great. It makes perfect sense to do it that way, thankyou for your contribution.

One small thing, please fix according to @jh0ker comment on updater.py, line 160. Then we can merge.

Comment thread telegram/ext/updater.py Outdated
self.running = True

# Create & start threads
self._init_thread(self.job_queue.start, "job_queue")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 @jh0ker comment here.
@wronglink can you please fix?

@wronglink

Copy link
Copy Markdown
Contributor Author

@jh0ker @tsnoam I've updated PR and added deprecation warning about prevent_autostart, so I guess it could be merged in 5.2.

@tsnoam

tsnoam commented Sep 26, 2016

Copy link
Copy Markdown
Member

for some reason, i couldn't see the sources with decreased coverage. i'm attempting rebuild with travis, maybe it'll help.

@wronglink

Copy link
Copy Markdown
Contributor Author

@tsnoam I've merged master branch, so forced TravisCI to recalculate coverage. Now files with decreased coverage are showed on coveralls.

@tsnoam

tsnoam commented Sep 27, 2016

Copy link
Copy Markdown
Member

@wronglink
thanks for that.
seems like the decrease in coverage is due to removed lines, changing stats in 0.1%. so i'm going merge now.
thanks again for your contribution.

@tsnoam
tsnoam merged commit 46657af into python-telegram-bot:master Sep 27, 2016
@wronglink
wronglink deleted the dont-start-threads-on-init branch September 28, 2016 11:48
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 24, 2020
@Bibo-Joshi Bibo-Joshi added 🔌 enhancement pr description: enhancement and removed enhancement labels Nov 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

🔌 enhancement pr description: enhancement 📋 pending-reply work status: pending-reply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants