-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Start additional threads only when necessary #415
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
Merged
tsnoam
merged 6 commits into
python-telegram-bot:master
from
wronglink:dont-start-threads-on-init
Sep 27, 2016
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eccc3f7
Start all additional threads only when necessary
wronglink a0452ae
Added myself to AUTHORS.rst
wronglink 8347d2d
Merge remote-tracking branch 'upstream/master' into dont-start-thread…
wronglink dba7490
Codereview fixes
wronglink 6a2a8a9
Edited deprecation text
wronglink 6ecd7b6
Merge remote-tracking branch 'upstream/master' into dont-start-thread…
wronglink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
|
|
||
| import logging | ||
| import time | ||
| import warnings | ||
| from threading import Thread, Lock, Event | ||
| from queue import PriorityQueue, Empty | ||
|
|
||
|
|
@@ -30,15 +31,19 @@ class JobQueue(object): | |
| Attributes: | ||
| queue (PriorityQueue): | ||
| bot (Bot): | ||
| prevent_autostart (Optional[bool]): If ``True``, the job queue will not be started | ||
| automatically. Defaults to ``False`` | ||
|
|
||
| Args: | ||
| bot (Bot): The bot instance that should be passed to the jobs | ||
|
|
||
| Deprecated: 5.2 | ||
| prevent_autostart (Optional[bool]): Thread does not start during initialisation. | ||
| Use `start` method instead. | ||
| """ | ||
|
|
||
| def __init__(self, bot, prevent_autostart=False): | ||
| def __init__(self, bot, prevent_autostart=None): | ||
| if prevent_autostart is not None: | ||
| warnings.warn("prevent_autostart is being deprecated, use `start` method instead.") | ||
|
|
||
| self.queue = PriorityQueue() | ||
| self.bot = bot | ||
| self.logger = logging.getLogger(self.__class__.__name__) | ||
|
|
@@ -51,12 +56,8 @@ def __init__(self, bot, prevent_autostart=False): | |
| """:type: float""" | ||
| self._running = False | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| if not prevent_autostart: | ||
| self.logger.debug('Auto-starting %s', self.__class__.__name__) | ||
| self.start() | ||
|
|
||
| def put(self, job, next_t=None): | ||
| """Queue a new job. If the JobQueue is not running, it will be started. | ||
| """Queue a new job. | ||
|
|
||
| Args: | ||
| job (Job): The ``Job`` instance representing the new job | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.