예제 #1
0
파일: base.py 프로젝트: Anthony25/barython
 def continuous_update(self):
     while not self._stop.is_set():
         try:
             self.update()
         except Exception as e:
             logger.error(e)
         splitted_sleep(self.refresh, stop=self._stop.is_set)
예제 #2
0
파일: base.py 프로젝트: Anthony25/barython
 def handler(self, *args, **kwargs):
     """
     To use with hooks
     """
     with self._lock_update:
         self.update()
         splitted_sleep(self.refresh, stop=self._stop.is_set)
예제 #3
0
 def notify(self, *args, **kwargs):
     for c in self.callbacks:
         try:
             threading.Thread(target=c, args=args, kwargs=kwargs).start()
         except Exception as e:
             logger.debug("Error in hook: {}".format(e))
             continue
     if self.refresh:
         splitted_sleep(self.refresh, stop=self._stop_event.is_set)
예제 #4
0
파일: bspwm.py 프로젝트: Anthony25/barython
 def handler(self, monitors, *args, **kwargs):
     """
     Filter events sent by notifications
     """
     new_content = self.decorate_with_self_attributes(
         self.organize_result(monitors)
     )
     with self._lock_update:
         self._update_screens(new_content)
         splitted_sleep(self.refresh, stop=self._stop.is_set)
예제 #5
0
파일: audio.py 프로젝트: Anthony25/barython
 def handler(self, event, *args, **kwargs):
     """
     Filter events sent by notifications
     """
     # Only notify if there is something changes in pulseaudio
     event_change_msg = "Event 'change' on destination"
     if event_change_msg in event:
         logger.debug("PA: line \"{}\" catched.".format(event))
         with self._lock_update:
             self.update()
             splitted_sleep(self.refresh, stop=self._stop.is_set)
예제 #6
0
파일: xorg.py 프로젝트: Anthony25/barython
 def run(self):
     # Import locally to not globalize the subscriptions to the entire file
     import xpybutil
     self.subscribe_to(xpybutil)
     while not self._stop_event.is_set():
         try:
             xpybutil.event.read()
             if len(xpybutil.event.peek()):
                 logger.debug("Xorg events received")
                 self.notify(
                     **self.parse_event(events=xpybutil.event.queue())
                 )
         except Exception as e:
             logger.error(e)
         finally:
             splitted_sleep(self.refresh, stop=self._stop_event.is_set)
예제 #7
0
파일: base.py 프로젝트: Anthony25/barython
 def continuous_update(self):
     while not self._stop.is_set():
         try:
             self.update()
         except Exception as e:
             logger.error(e)
             try:
                 self._subproc.terminate()
             except:
                 pass
         finally:
             splitted_sleep(self.refresh, stop=self._stop.is_set)
             self.notify()
     try:
         self._subproc.terminate()
     except:
         pass
예제 #8
0
파일: mpd.py 프로젝트: Anthony25/barython
 def run(self):
     # killed will be here to track the last state of the connection. We
     # start at True to force the first print.
     killed = True
     while not self._stop_event.is_set():
         try:
             if killed:
                 # test the connection and notify to force printing the
                 # current song, as idle() will wait for any change in mpd
                 self._mpdclient.ping()
                 self._mpdclient.send_idle()
                 try:
                     self.notify(**self.parse_event(run=True))
                 except Exception as e:
                     logger.error(e)
                 killed = False
             else:
                 # wait for any change in mpd and then notify
                 changes = select.select([self._mpdclient], [], [], self.refresh)
                 if not changes[0]:
                     continue
                 notify_kwargs = self.parse_event(self._mpdclient.fetch_idle())
                 try:
                     self.notify(**notify_kwargs)
                 except Exception as e:
                     logger.error(e)
                 self._mpdclient.send_idle()
         except:
             killed = True
             try:
                 self._mpdclient.connect(self.host, self.port)
             except:
                 logger.error("MPD is maybe not running or host/port are not correct")
                 try:
                     notify_kwargs = self.parse_event(run=False)
                     try:
                         self.notify(**notify_kwargs)
                     except Exception as e:
                         logger.error(e)
                 except:
                     pass
             finally:
                 splitted_sleep(self.refresh, stop=self._stop_event.is_set)
예제 #9
0
 def run(self):
     while not self._stop_event.is_set():
         try:
             self._subproc = self._init_subproc()
             line = self._subproc.stdout.readline()
             notify_kwargs = self.parse_event(
                 line.decode().replace('\n', '').replace('\r', '')
             )
             self.notify(**notify_kwargs)
             subproc_poll = self._subproc.poll()
             if subproc_poll is not None and subproc_poll != 0:
                 splitted_sleep(self.failure_refresh,
                                stop=self._stop_event.is_set)
         except Exception as e:
             logger.error("Error when reading line: {}".format(e))
             try:
                 self._subproc = self._subproc.kill()
             except:
                 pass
     try:
         self._subproc = self._subproc.kill()
     except:
         pass
예제 #10
0
def test_splitted_sleep(mocker):
    mocker.patch("barython.tools.time.sleep")
    mocker.spy(barython.tools.time, "sleep")
    splitted_sleep(2, 0.5)
    assert barython.tools.time.sleep.call_count == 4