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

Async mode fix #29

Merged
merged 32 commits into from
Jan 18, 2024
Merged

Async mode fix #29

merged 32 commits into from
Jan 18, 2024

Conversation

sepandhaghighi
Copy link
Member

Reference Issues/PRs

#5 #27 #26

What does this implement/fix? Explain your changes.

  • NavaThread class added
  • stop function added
  • stop_all function added
  • autopep8 scripts updated
  • README.md updated
  • CHANGELOG.md updated

Any other comments?

@sepandhaghighi sepandhaghighi added enhancement New feature or request refactoring labels Jan 16, 2024
@sepandhaghighi sepandhaghighi added this to the nava v0.3 milestone Jan 16, 2024
@sepandhaghighi sepandhaghighi self-assigned this Jan 16, 2024
Copy link

codecov bot commented Jan 16, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (78992c6) 69.13% compared to head (435e701) 99.16%.

Files Patch % Lines
nava/thread.py 94.44% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              dev      #29       +/-   ##
===========================================
+ Coverage   69.13%   99.16%   +30.03%     
===========================================
  Files           3        4        +1     
  Lines          81      120       +39     
  Branches        7       12        +5     
===========================================
+ Hits           56      119       +63     
+ Misses         24        0       -24     
  Partials        1        1               

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sepandhaghighi sepandhaghighi marked this pull request as ready for review January 16, 2024 22:23
@sadrasabouri
Copy link
Member

sadrasabouri commented Jan 17, 2024

Local tests on OSs

  • MacOS Sonoma 14.2.1
  • Windows 10
  • Ubuntu 16.04
  • Ubuntu 22.04

Copy link
Member

@sadrasabouri sadrasabouri left a comment

Choose a reason for hiding this comment

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

Thanks for your efforts. That was a great job.

:param kwargs: keyword arguments
:type kwargs: dict
"""
super(NavaThread, self).__init__(*args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

According to super, you are trying to limit the parental initialization only to the NavaThread class, right?

Copy link
Member Author

@sepandhaghighi sepandhaghighi Jan 18, 2024

Choose a reason for hiding this comment

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

Yeah, it will help NavaThread to act like the original Thread in other aspects.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see. It seems a high-level trick. 🥇

sys_platform = sys.platform
if sys_platform == "win32":
import winsound
winsound.PlaySound(None, winsound.SND_PURGE)
Copy link
Member

Choose a reason for hiding this comment

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

Did you test the case in Windows where you have multiple sounds playing asynchronously and try to stop just one of them?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, the winsound module cannot play multiple sounds simultaneously. But play/stop of one sound in async mode works like charm!

CHANGELOG.md Outdated
@@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Async mode
Copy link
Member

Choose a reason for hiding this comment

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

I think "async_mode parameter" under Changed is better.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed --> 435e701

:return: sound id as int
"""
params._play_threads_counter += 1
sound_id = params._play_threads_counter + 1000
Copy link
Member

Choose a reason for hiding this comment

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

Why did you add 1000 offset. If it's necessary, what do you think of transferring it to params.

Copy link
Member Author

Choose a reason for hiding this comment

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

For better readability, we may change the format of the sound_id to something like Nava-1, Nava-2, etc. in the future.

play_flags = winsound.SND_FILENAME | (async_mode & winsound.SND_ASYNC)

if async_mode:
sound_thread = NavaThread(target=__play_win_flags, args=(sound_path, play_flags), daemon=True)
Copy link
Member

Choose a reason for hiding this comment

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

It's too long. Can you make it multiline?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed --> b0f52fc

Copy link
Member

@sadrasabouri sadrasabouri left a comment

Choose a reason for hiding this comment

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

Well done. Thanks

@sadrasabouri sadrasabouri merged commit 9b166c4 into dev Jan 18, 2024
62 checks passed
@sadrasabouri sadrasabouri deleted the async_fix branch January 18, 2024 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants