ranger-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Ranger-users] Writing asynchronous plugins


From: Hut
Subject: Re: [Ranger-users] Writing asynchronous plugins
Date: Mon, 28 Apr 2014 02:01:47 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

On Sun, Apr 27, 2014 at 09:49:24PM +0200, Matthias Vogelgesang wrote:
> - How do I implement asynchronous calls to external programs?
> Currently, I run a runner with the wait flag set to False. In another
> thread I wait for the process to finish and update the affected
> directory.

ranger is a single-threaded program and it deals with background processes like
copying or loading directories by alternating between the UI and the background
process during the time the user takes to type keys.  The module which
implements this is ranger.core.loader.

External commands can be run via the class CommandLoader.  It sends a signal
when the command finishes, so you can execute some code without a second thread
by binding a function to this signal.  You can see an example of the usage of
this class in the code that executes scope.sh, it is located at
ranger/core/actions.py in the method Actions.get_preview().

Here's a short example containing the essentials:

> loadable = CommandLoader(args=["yourcommand", "arg1", "arg2"], descr="Doing 
> Stuff")
> def on_after(signal):
>     process = signal.process
>     loader = signal.loader
>     exitcode = process.poll()
>     loader.fm.notify("The process has finished with the exit code %d!" % 
> exitcode)
> loadable.signal_bind("after", on_after)
> self.fm.loader.add(loadable)  # assuming self is a subclass of 
> FileManagerAware


> - Is it okay to save fm.thisdir and use it later in another thread?

To be honest, I don't know.  However, if you use CommandLoader, as suggested,
you won't need to use threads and can avoid this problem entirely.


> - How can I notify the user that a certain action is currently going
> on and taking a while?

If you use the loader, the process will be added into the Task View (just like
copying or loading directories) which can be entered by typing "w".  Note that
the user will be able to kill the process by typing "dd" too.


And sorry for the lack of documentation.  If you want to know something else
about the code, just ask away.

Regards,
hut



reply via email to

[Prev in Thread] Current Thread [Next in Thread]