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

Implemented a thread for opening a file using mmap in the decrypt_fil… #82

Closed
wants to merge 1 commit into from

Conversation

technokowski
Copy link

Implemented a thread for opening a file using mmap in the decrypt_file() function in /gui/app.py. It was listed as a TODO item to replace the with open() call.

…e() function in /gui/app.py. It was listed as a TODO item to replace the with open() call.
@codecov
Copy link

codecov bot commented Feb 8, 2022

Codecov Report

Merging #82 (2112d6c) into main (24c63e7) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #82   +/-   ##
=======================================
  Coverage   74.96%   74.96%           
=======================================
  Files          23       23           
  Lines        2169     2169           
  Branches      509      509           
=======================================
  Hits         1626     1626           
  Misses        422      422           
  Partials      121      121           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24c63e7...2112d6c. Read the comment docs.

# with open(file, "rb") as f:
# data = f.read()
# MY FIX
with open(file, mode="r", encoding="utf8") as f:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure what the original intention / objective was, but this is not a threading solution. Creating an mmap object and reading through it does does not prevent blocking the single threaded application.

Also, please do not leave old code uncommented intact.

Copy link
Author

Choose a reason for hiding this comment

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

Apologies, I thought I had removed the commented code. I had some issues with setting up the repo. I'll make sure to remove it.
As for the question, there was a TODO item commented out prior to my fix. This was an attempt to change regular python I/O to an mmap equivalent I/O. Perhaps I misunderstood the TODO, but it wasn't meant to be a final fix. I was focusing on speeding up the performance of the file read time, which I achieved. My tests show a speed difference from the previous code.
If that was not the intention of the TODO, please disregard.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm guessing the original intent was to improve responsiveness of the GUI when a large file is being decrypted. But I don't know what the original author intended. @covert-encryption Do we have a clear target? Anyway, there should be a use-case that clearly shows that the current approach produces undesired effects, after which we can test new solutions to fix the issue, if any.

Copy link
Owner

Choose a reason for hiding this comment

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

@heikkiorsila I believe he picked unfinished checkboxes from #37. Yes, the intent is responsiveness, especially when files of several gigabytes are being processed.

@technokowski The GUI freezes, "app not responding", until the SLOT function returns. Thus any long-running operations should be performed in background threads instead, and any event handlers should return (almost) immediately.

This is not an easy task to do, because it will need a ThreadPoolExecutor or plain thread handles somewhere (like in the main application object) to keep running any threaded tasks in the background without disturbing the GUI. Note that the threads cannot call any GUI code but instead the GUI also needs to run a QTimer that periodically checks for threads' results or progress made e.g. every 100 ms.

If you are not already familiar with threads, I would suggest starting with some easier things instead. Contributions on the GUI would certainly be most welcome, although you may find tasks within the CLI/core a good starting point at familiarising yourself with the project first.

Within the GUI, supporting drag&drop of attachment files and displaying image files (or other media) directly inside the GUI would be nice, and fairly isolated from other functions so you don't need to look much at other code. The current way that attachments are displayed (both in the new message dialog, and in the decrypt view) may be entirely replaced if you find another way of implementing them better.

Please always use the b mode for file I/O as in the original code, instead of text mode I/O that has various issues (like handling newlines differently depending on platform, which we don't want).

@technokowski technokowski marked this pull request as draft February 9, 2022 13:41
@covert-encryption
Copy link
Owner

Closing as no further comments have been made and it doesn't seem likely for this to advance.

@technokowski Feel free to make another PR if you wish to work on some other part, or reopen this if you plan to advance with this one. Any contributions are appreciated.

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

3 participants