question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to best pass file ownership from imopen to a plugin?

See original GitHub issue

The basic idea behind the file-management of the new API is simple:

with iio.imopen(...) as img_file:
    img = img_file.read(...)
    ...

The file is opened by imopen, held by img_file during the context, and closed once the context manager exits. This works nicely.

A problem occurs when we use imopen outside a context manager:

instance = iio.imopen(...)
# ... program crashes or returns here
instance.read(...)

In this case, the open file may not be cleaned up properly or could cause a dangling reference. How can we smooth this out?

One option would be to have imopen close the file after it is done selecting a plugin and have the plugin reopen it. This might work, but is undesirable because it slows down the default case of using imopen inside a context manager (as intended)

Another option would be to use a promise-style setup where imopen returns a PluginPromise which gets turned into the correct plugin by its __enter__ method. This would ensure that all file access is properly guarded. Promise-based interfaces are more common in JS than they are in python though, so I don’t know if this idea is easily maintainable.

A third option could be to make the destructor of imopen close the file. However, this may limit applications, because they cant use the file outside imopen’s scope.

All the options have pros and cons. The question here is which option is the best.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
almarkleincommented, Nov 3, 2021

Do we actually use it anywhere?

No, but maybe we should make sure that we don’t with a test, so that it stays that way

1reaction
FirefoxMetzgercommented, Nov 2, 2021

@almarklein I think a Plugin class could be nice, indeed. That way, we can avoid boilerplate, but also get some typing support, because imopen can now define Plugin as a return type.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FileOpen Plugin For Adobe Reader/Acrobat Troubleshooting ...
2) When installing the FileOpen Plugin I get the error, "FileOpen Manager Service could not be installed. Verify that you have sufficient privileges...
Read more >
Transfer ownership of files or projects – Figma Help Center
Click Share at the top of the page to open the share modal. Click their existing permissions and select Owner. Click the Transfer...
Read more >
Why can't the plugin overwrite a file or create a backup? What ...
The Unix systems (this includes Linux in all its flavors and distributions) have permissions and ownership for each file (read more here).
Read more >
Bypass, remove, or rescan Audio Units plug-ins in Logic Pro ...
Find the installed plug-in file on your Mac: ... Move all the plug-in files that appear in their installation locations to the new...
Read more >
How do I open a web browser (URL) from my Flutter code?
Add url_launcher as a dependency in your pubspec.yaml file. ... You can pass forceWebView: true parameter to tell the plugin to open a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found