S
S
ssclock2015-10-30 17:47:02
linux
ssclock, 2015-10-30 17:47:02

How to insert a pause in the execution of a python script?

There is a Linux player Rhythmbox and a plug-in for it - Remember the rhythm, which records the time the song is played in dconf, and if the player is closed, it allows playback to be restored from that time.
The problem is that it writes every second, if not more, which is why dconf-service eats up more than two percent of the processor. After reading the code, I did not see a key there that determines the frequency of recording. Is there such a key there or is it possible to add it there, even if only by roughly pausing the execution of the entire script?
Script text: https://github.com/owais/remember-the-rhythm/blob/...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alpy, 2015-11-01
@ssclock


After reading the code, I did not see a key there that determines the frequency of recording. Is there such a key there or is it possible to add it there, even if only by roughly pausing the execution of the entire script?

def do_activate ...
    self.shell_player.connect('elapsed-changed', self.elapsed_changed)

Here the plugin subscribes to a position change signal, which happens every second. Accordingly, the elapsed_changed call will also occur every second. A simple sleep will most likely not help here, because. the player must pull functions on signals in a non-blocking manner.
I would try rewriting elapsed_changed like this:
def elapsed_changed(self, player, entry, data=None):
    try:
        pb_time = self.shell_player.get_playing_time()[1]
        if pb_time % 5 == 0:
            self.playback_time = self.shell_player.get_playing_time()[1]
    except:
        pass

in this case the position is fixed every 5th second

A
angru, 2015-10-30
@angru

time.sleep

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question