Skip to content

Conversation

@olivierdelree
Copy link
Contributor

Closes #6.

This was tested on Linux and Windows, and will be merged once it is tested on macOS.

@celefthe Could you check if you can create projects fine on macOS with this branch?

The comment explains it all, To avoid `zlib` blowing up the memory
usage, we need to reduce the chunk size a lot.
The downloads are now done in chunks, allowing an optional callback
to be provided which is checked between every chunk. The callback is
expected to return a boolean dictating whether to cancel the download
or not.
@olivierdelree olivierdelree self-assigned this Aug 13, 2025
@olivierdelree olivierdelree added the bug Something isn't working label Aug 13, 2025
@olivierdelree
Copy link
Contributor Author

Actually, never mind. It's still not working to cancel a load.

@olivierdelree olivierdelree marked this pull request as draft August 14, 2025 09:12
@olivierdelree
Copy link
Contributor Author

I'm giving up for now, pickling should be fixed but allowing cancellation is not and remains disabled.

@olivierdelree olivierdelree marked this pull request as ready for review August 14, 2025 14:24
@olivierdelree olivierdelree requested review from celefthe and removed request for celefthe August 14, 2025 14:25
@olivierdelree
Copy link
Contributor Author

Sorry, not for review, but for testing on macOS...

This drops the use of `multiprocessing.Process` objects to (down)load
volumes, which should fix the pickling troubles on macOS.

Additionally, the thread can now react to interruption requests and
gracefully cancels downloads or abruptly terminates loads.
This allows calling code to handle cases where the user cancelled the
(down)load.
This makes use of processes to load NumPy arrays of the volumes in a
separate environment, allowing it to be cancelled without freezing the
main GUI. Additionally, the normalisation can now be done "fast",
meaning that now floating, intermediary arrays are used, saving a bit
of speed and a lot of memory.
@olivierdelree olivierdelree changed the title Remove dependency on multiprocessing.Process to (down)load volumes and re-enable (down)load cancelling Fix pickling issue with multiprocessing.Process to (down)load volumes and re-enable (down)load cancelling Aug 18, 2025
@olivierdelree
Copy link
Contributor Author

There you go. Now mostly works, although the GUI still freezes a bit towards the end of the loading, when merging with the main thread.

@olivierdelree olivierdelree marked this pull request as draft October 13, 2025 13:25
@celefthe
Copy link
Member

Is this still being drafted atm? Still seeing the same issue on MacOS

@celefthe
Copy link
Member

Well I'm seeing the following

Error calling Python override of QThread::run(): Traceback (most recent call last):
  File "/Users/celefthe/.local/share/uv/tools/histalign/lib/python3.11/site-packages/histalign/backend/workspace/__init__.py", line 326, in run
    process.start()
  File "/Users/celefthe/.pyenv/versions/3.11.5/lib/python3.11/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
                  ^^^^^^^^^^^^^^^^^
  File "/Users/celefthe/.pyenv/versions/3.11.5/lib/python3.11/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
Error calling Python override of QThread::run(): Traceback (most recent call last):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/celefthe/.pyenv/versions/3.11.5/lib/python3.11/multiprocessing/context.py", line 288, in _Popen
  File "/Users/celefthe/.local/share/uv/tools/histalign/lib/python3.11/site-packages/histalign/backend/workspace/__init__.py", line 326, in run
    process.start()
  File "/Users/celefthe/.pyenv/versions/3.11.5/lib/python3.11/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
                  ^^^^^^^^^^^^^^^^^
  File "/Users/celefthe/.pyenv/versions/3.11.5/lib/python3.11/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/celefthe/.pyenv/versions/3.11.5/lib/python3.11/multiprocessing/context.py", line 288, in _Popen
    return Popen(process_obj)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/celefthe/.pyenv/versions/3.11.5/lib/python3.11/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    return Popen(process_obj)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/celefthe/.pyenv/versions/3.11.5/lib/python3.11/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Users/celefthe/.pyenv/versions/3.11.5/lib/python3.11/multiprocessing/popen_fork.py", line 19, in __init__
    super().__init__(process_obj)
  File "/Users/celefthe/.pyenv/versions/3.11.5/lib/python3.11/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
    self._launch(process_obj)
  File "/Users/celefthe/.pyenv/versions/3.11.5/lib/python3.11/multiprocessing/popen_spawn_posix.py", line 47, in _launch
  File "/Users/celefthe/.pyenv/versions/3.11.5/lib/python3.11/multiprocessing/popen_spawn_posix.py", line 47, in _launch
    reduction.dump(process_obj, fp)
  File "/Users/celefthe/.pyenv/versions/3.11.5/lib/python3.11/multiprocessing/reduction.py", line 60, in dump
    reduction.dump(process_obj, fp)
  File "/Users/celefthe/.pyenv/versions/3.11.5/lib/python3.11/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
TypeError: cannot pickle 'AnnotationVolume' object
    ForkingPickler(file, protocol).dump(obj)
TypeError: cannot pickle 'Volume' object

@olivierdelree
Copy link
Contributor Author

Should have be fixed by ab00 on main.

@olivierdelree
Copy link
Contributor Author

But the PR is mostly dead. I might revisit it later but will need to have a better look at completely changing the way volumes are loaded to ensure no pickling is necessary.

@celefthe
Copy link
Member

Ah right yes I was running the released version instead of the one currently on main, works fine now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants