Let’s say we have a text widget which displays output of some script (get unread emails for instance). And sometimes execution of this script takes some time. Since lua is not multi-threaded you’ll have a ‘freeze’ - you won’t be able to interact with Awesome (switch tags, open Awesome menu, etc.) because Awesome will wait for the response.
I will demonstrate it on a simple example. Let’s say I have a python script which sleeps for 5 seconds and then returns some string, sleep.py:
By using awful.util.pread Awesome will just wait until execution of a script is finished. To check it let’s create a text widget in a separate lus file:
And put it in rc.lua:
After restart of Awesome after 5 seconds Awesome will freeze for 5 seconds and then message will be displayed on a widget. This is exactly what happens when execution of some scripts takes time.
Now let’s have on a solution of this problem: using DBus to transfer messages between scripts and Awesome.
To use DBus for this example change implementation of sleep.py
With this implementation Awesome will not freeze. Here instead of reading output of a script we send it to DBus:
And when execution has finished we take it and display:
For widgets, which uses scripts which could take some time to run, like calling some service use DBus :)