Philipp Hörist pushed to branch master at gajim / gajim
Commits: 4dff3a2d by lovetox at 2022-01-18T13:40:21+01:00 Revert behavior of write_file_async()
Seems Python collects variables as soon as they are not needed anymore, even if the function has not ended. This means we have to someway use `data` even with nested function callbacks.
- - - - -
1 changed file:
- gajim/common/helpers.py
Changes:
===================================== gajim/common/helpers.py ===================================== @@ -1280,7 +1280,8 @@ def write_file_async( user_data: Optional[Any] = None):
def _on_write_finished(outputstream: Gio.OutputStream, - result: Gio.AsyncResult) -> None: + result: Gio.AsyncResult, + _data: bytes) -> None: try: successful, _bytes_written = outputstream.write_all_finish(result) except GLib.Error as error: @@ -1295,10 +1296,14 @@ def _on_file_created(file: Gio.File, result: Gio.AsyncResult) -> None: callback(False, error, user_data) return
+ # Pass data as user_data to the callback, because + # write_all_async() takes no reference to the data + # and python gc collects it before the data is written outputstream.write_all_async(data, GLib.PRIORITY_DEFAULT, None, - _on_write_finished) + _on_write_finished, + data)
file = Gio.File.new_for_path(str(path)) file.create_async(Gio.FileCreateFlags.PRIVATE,
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/4dff3a2dd4e95e9de3eba9c69398bef9e...