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

Eliminate timeout in waiting on event queue #861

Merged
merged 4 commits into from Dec 11, 2021

Conversation

sattlerc
Copy link
Contributor

The use of a timeout in reading from the event queue in BaseObserver is a hack. This causes an unnecessary wake-up every second and causes the following program to take one second:

from watchdog.observers import Observer
observer = Observer()
observer.start()
observer.stop()
observer.join()

This pull request gets rid of the timeout by adding a null event to the event queue after a stop is requested.

Note that, contrary to documentation, this timeout value was also used for other things than reading from the event queue. It is also passed to emitters constructed in BaseObserver. I have thus left the timeout attribute in place and instead fixed its documentation.

@BoboTiG
Copy link
Collaborator

BoboTiG commented Dec 11, 2021

Thanks @sattlerc. Do you mind adding a line + your GitHub username in the changelog.rst file 🙏 ?

changelog.rst Outdated Show resolved Hide resolved
@BoboTiG BoboTiG merged commit 61d8f86 into gorakhargosh:master Dec 11, 2021
mergify bot pushed a commit to andrewbolster/bolster that referenced this pull request Mar 25, 2022
Bumps [watchdog](https://github.com/gorakhargosh/watchdog) from 2.1.6 to 2.1.7.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/gorakhargosh/watchdog/releases">watchdog's releases</a>.</em></p>
<blockquote>
<h2>2.1.7</h2>
<ul>
<li>Eliminate timeout in waiting on event queue. (<a href="https://github-redirect.dependabot.com/gorakhargosh/watchdog/issues/861">#861</a>)</li>
<li>[inotify] Fix <code>not</code> equality implementation for <code>InotifyEvent</code>. (<a href="https://github-redirect.dependabot.com/gorakhargosh/watchdog/issues/848">#848</a>)</li>
<li>[watchmedo] Fix calling commands from within a Python script. (<a href="https://github-redirect.dependabot.com/gorakhargosh/watchdog/issues/879">#879</a>)</li>
<li>[watchmedo] <code>PyYAML</code> is loaded only when strictly necessary. Simple usages of <code>watchmedo</code> are possible without the module being installed. (<a href="https://github-redirect.dependabot.com/gorakhargosh/watchdog/issues/847">#847</a>)</li>
</ul>
<p>:heart_decoration: Thanks to our beloved contributors: <a href="https://github.com/sattlerc"><code>@​sattlerc</code></a>, <a href="https://github.com/JanzenLiu"><code>@​JanzenLiu</code></a>, <a href="https://github.com/BoboTiG"><code>@​BoboTiG</code></a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/gorakhargosh/watchdog/blob/master/changelog.rst">watchdog's changelog</a>.</em></p>
<blockquote>
<p>2.1.7</p>
<pre><code>
2022-03-25 • `full history &lt;https://github.com/gorakhargosh/watchdog/compare/v2.1.6...v2.1.7&gt;`__
<ul>
<li>Eliminate timeout in waiting on event queue. (<code>[#861](gorakhargosh/watchdog#861) &amp;lt;https://github.com/gorakhargosh/watchdog/pull/861&amp;gt;</code>_)</li>
<li>[inotify] Fix <code>not</code> equality implementation for <code>InotifyEvent</code>. (<code>[#848](gorakhargosh/watchdog#848) &amp;lt;https://github.com/gorakhargosh/watchdog/pull/848&amp;gt;</code>_)</li>
<li>[watchmedo] Fix calling commands from within a Python script. (<code>[#879](gorakhargosh/watchdog#879) &amp;lt;https://github.com/gorakhargosh/watchdog/pull/879&amp;gt;</code>_)</li>
<li>[watchmedo] <code>PyYAML</code> is loaded only when strictly necessary. Simple usages of <code>watchmedo</code> are possible without the module being installed. (<code>[#847](gorakhargosh/watchdog#847) &amp;lt;https://github.com/gorakhargosh/watchdog/pull/847&amp;gt;</code>_)</li>
<li>Thanks to our beloved contributors: <a href="https://github.com/sattlerc"><code>@​sattlerc</code></a>, <a href="https://github.com/JanzenLiu"><code>@​JanzenLiu</code></a>, <a href="https://github.com/BoboTiG"><code>@​BoboTiG</code></a>
</code></pre></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/gorakhargosh/watchdog/commit/4641ccdb281a00ae76a36a1ce1e5da9a71e70724"><code>4641ccd</code></a> Release 2.1.7</li>
<li><a href="https://github.com/gorakhargosh/watchdog/commit/be50c422288e721dc864f453ca93ef21113c6977"><code>be50c42</code></a> [watchmedo] Fix calling commands from within a Python script (<a href="https://github-redirect.dependabot.com/gorakhargosh/watchdog/issues/880">#880</a>)</li>
<li><a href="https://github.com/gorakhargosh/watchdog/commit/77e1f4668bc42b4a8706b181d882fd68c05ab8b9"><code>77e1f46</code></a> Fix typo in README (<a href="https://github-redirect.dependabot.com/gorakhargosh/watchdog/issues/866">#866</a>)</li>
<li><a href="https://github.com/gorakhargosh/watchdog/commit/f945d826b102598e877b34e8feeabd5693801a08"><code>f945d82</code></a> Fix pypy CI version (<a href="https://github-redirect.dependabot.com/gorakhargosh/watchdog/issues/864">#864</a>)</li>
<li><a href="https://github.com/gorakhargosh/watchdog/commit/3d5c4f9a4b73701fb68ebbe7a5bdd87df6197fb0"><code>3d5c4f9</code></a> Run Github actions on master (<a href="https://github-redirect.dependabot.com/gorakhargosh/watchdog/issues/863">#863</a>)</li>
<li><a href="https://github.com/gorakhargosh/watchdog/commit/fa3b3b58925ac60612eed4554a99e721365a2580"><code>fa3b3b5</code></a> [watchmedo] Lazy loading of the PyYAML module (<a href="https://github-redirect.dependabot.com/gorakhargosh/watchdog/issues/847">#847</a>)</li>
<li><a href="https://github.com/gorakhargosh/watchdog/commit/5f895488b314295ecba9351d94ad0d2f4dcab6c3"><code>5f89548</code></a> [inotify] Fix <code>not</code> equality implementation for <code>InotifyEvent</code></li>
<li><a href="https://github.com/gorakhargosh/watchdog/commit/61d8f86975abc828acdf87f6fc4da74253811ccd"><code>61d8f86</code></a> Eliminate timeout in waiting on event queue (<a href="https://github-redirect.dependabot.com/gorakhargosh/watchdog/issues/861">#861</a>)</li>
<li><a href="https://github.com/gorakhargosh/watchdog/commit/57e80a504035892772858d018df542ffb3da0bf3"><code>57e80a5</code></a> Bump the version to 2.1.7</li>
<li>See full diff in <a href="https://github.com/gorakhargosh/watchdog/compare/v2.1.6...v2.1.7">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=watchdog&package-manager=pip&previous-version=2.1.6&new-version=2.1.7)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>
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

Successfully merging this pull request may close these issues.

None yet

2 participants