def doIteration(self, delay):
# flush some pending events, return if there was something to do
# don't use the usual "while self.context.pending(): self.context.iteration()"
# idiom because lots of IO (in particular test_tcp's
# ProperlyCloseFilesTestCase) can keep us from ever exiting.
log.msg(channel='system', event='iteration', reactor=self)
if self.__pending():
self.__iteration(0)
return
# nothing to do, must delay
if delay == 0:
return # shouldn't delay, so just return
self.doIterationTimer = gobject.timeout_add(int(delay * 1000),
self.doIterationTimeout)
# This will either wake up from IO or from a timeout.
self.__iteration(1) # block
# note: with the .simulate timer below, delays > 0.1 will always be
# woken up by the .simulate timer
if self.doIterationTimer:
# if woken by IO, need to cancel the timer
gobject.source_remove(self.doIterationTimer)
self.doIterationTimer = None
python类source_remove()的实例源码
def close(self):
PlayerSource.close(self)
if self.io_watcher_id is not None:
gobject.source_remove(self.io_watcher_id)
self.io_watcher_id = None
if self.data:
self.data.close()
self.data = None
if self.control:
self.control.close()
self.control = None
if self.fifo:
self.fifo.close()
self.fifo = None
self.fifo_name = None
return True
# close()
# PlayerSourceGMythStreamer
def doIteration(self, delay):
# flush some pending events, return if there was something to do
# don't use the usual "while self.context.pending(): self.context.iteration()"
# idiom because lots of IO (in particular test_tcp's
# ProperlyCloseFilesTestCase) can keep us from ever exiting.
log.msg(channel='system', event='iteration', reactor=self)
if self.__pending():
self.__iteration(0)
return
# nothing to do, must delay
if delay == 0:
return # shouldn't delay, so just return
self.doIterationTimer = gobject.timeout_add(int(delay * 1000),
self.doIterationTimeout)
# This will either wake up from IO or from a timeout.
self.__iteration(1) # block
# note: with the .simulate timer below, delays > 0.1 will always be
# woken up by the .simulate timer
if self.doIterationTimer:
# if woken by IO, need to cancel the timer
gobject.source_remove(self.doIterationTimer)
self.doIterationTimer = None
def start_timer(self, timer_type):
"""start given timer"""
#screen saver
if timer_type == 'scrsave' and self.scrsave_delay > 0:
if self.scrsave_timer:
gobject.source_remove(self.scrsave_timer)
self.scrsave_timer = gobject.timeout_add(2500, self.on_scrsave_timer)
#video
elif timer_type == 'video' and self.video_enabled:
#stop any playing vids first
self.stop_video()
#restart timer
self.video_timer = gobject.timeout_add(
self.delaymovieprev * 1000,
self.on_video_timer)
#joystick
elif timer_type == 'joystick' and self.joy:
self.joystick_timer = gobject.timeout_add(50, self.joy.poll, self.on_winMain_key_press)
def __init__(self, mapping=None, **kwargs):
# socket -> (source_id, mask) map, for io_add_watch and source_remove
self._watch_map = dict()
# fd -> socket map, for the interface
self._fd_map = dict()
if mapping is not None:
self.update(mapping)
if kwargs:
self.update(kwargs)
def _remove_watch(self, obj):
gobject.source_remove(self._watch_map.pop(obj)[0])
def removeReader(self, reader):
if hasReader(reader):
gobject.source_remove(reads[reader])
del reads[reader]
def removeWriter(self, writer):
if hasWriter(writer):
gobject.source_remove(writes[writer])
del writes[writer]
def simulate(self):
"""Run simulation loops and reschedule callbacks.
"""
global _simtag
if _simtag is not None:
gobject.source_remove(_simtag)
self.runUntilCurrent()
timeout = min(self.timeout(), 0.1)
if timeout is None:
timeout = 0.1
# grumble
_simtag = gobject.timeout_add(int(timeout * 1010), self.simulate)
def simulate(self):
"""Run simulation loops and reschedule callbacks.
"""
global _simtag
if _simtag is not None:
gobject.source_remove(_simtag)
self.iterate()
timeout = min(self.timeout(), 0.1)
if timeout is None:
timeout = 0.1
# grumble
_simtag = gobject.timeout_add(int(timeout * 1010), self.simulate)
def _start_update_timer(self):
if self._update_timeout_id is not None:
gobject.source_remove(self._update_timeout_id)
#print "start_update_timer"
self._update_timeout_id = gobject.timeout_add(int(SAMPLE_PERIOD/min(self.speed, 1)*1e3),
self.update_view_timeout,
priority=PRIORITY_UPDATE_VIEW)
def _on_play_button_toggled(self, button):
if button.get_active():
self._start_update_timer()
else:
if self._update_timeout_id is not None:
gobject.source_remove(self._update_timeout_id)
def _quit(self, *dummy_args):
if self._update_timeout_id is not None:
gobject.source_remove(self._update_timeout_id)
self._update_timeout_id = None
self.simulation.quit = True
self.simulation.go.set()
self.simulation.join()
gtk.main_quit()
def _refresh_keep_alive(self):
if self._keep_alive_interval is None:
return
restart = False
if self._keep_alive_timer is None:
logging.info('[KeepAlive] Received request, publishing restarted')
restart = True
else:
gobject.source_remove(self._keep_alive_timer)
self._keep_alive_timer = gobject.timeout_add_seconds(
self._keep_alive_interval, exit_on_error, self._on_keep_alive_timeout)
if restart:
# Do this after self._keep_alive_timer is set, because self._publish used it check if it should
# publish
self._publish_all()
def _init_socket_handlers(self):
if self._socket_watch is not None:
gobject.source_remove(self._socket_watch)
self._socket_watch = gobject.io_add_watch(self._client.socket().fileno(), gobject.IO_IN,
self._on_socket_in)
if self._socket_timer is None:
self._socket_timer = gobject.timeout_add_seconds(1, exit_on_error, self._on_socket_timer)
def _on_disconnect(self, client, userdata, rc):
logging.error('[Disconnected] Lost connection to broker')
if self._socket_watch is not None:
gobject.source_remove(self._socket_watch)
self._socket_watch = None
logging.info('[Disconnected] Set timer')
gobject.timeout_add(5000, exit_on_error, self._reconnect)
def cancel_benchmark(self):
self.stop_benchmark()
gobject.source_remove(self.countdown_event)
self.get('hbox_status').set_visible(False)
self.get('seconds_spinbox').set_sensitive(True)
self.get('hbox_buttons').set_visible(True)
def _unregister_state_timeout(self):
if self.state_timeout is not None:
gobject.source_remove(self.state_timeout)
self.state_timeout = None
# _unregister_state_timeout()
def stop(self):
self.dot_widget.animation = NoAnimation(self.dot_widget)
if self.timeout_id is not None:
gobject.source_remove(self.timeout_id)
self.timeout_id = None
def destroy(self, w):
if MPI_ENABLED:
if mpi.rank == 0:
if self.thread is None:
wake_nodes(1)
mpi.bcast(None)
else:
wake_nodes(3)
gobject.source_remove(self.pbar_timer)
gtk.main_quit()
def removeReader(self, reader):
if hasReader(reader):
gobject.source_remove(reads[reader])
del reads[reader]
def removeWriter(self, writer):
if hasWriter(writer):
gobject.source_remove(writes[writer])
del writes[writer]
def simulate(self):
"""Run simulation loops and reschedule callbacks.
"""
global _simtag
if _simtag is not None:
gobject.source_remove(_simtag)
self.runUntilCurrent()
timeout = min(self.timeout(), 0.1)
if timeout is None:
timeout = 0.1
# grumble
_simtag = gobject.timeout_add(int(timeout * 1010), self.simulate)
def simulate(self):
"""Run simulation loops and reschedule callbacks.
"""
global _simtag
if _simtag is not None:
gobject.source_remove(_simtag)
self.iterate()
timeout = min(self.timeout(), 0.1)
if timeout is None:
timeout = 0.1
# grumble
_simtag = gobject.timeout_add(int(timeout * 1010), self.simulate)
def stop(self):
self.dot_widget.animation = NoAnimation(self.dot_widget)
if self.timeout_id is not None:
gobject.source_remove(self.timeout_id)
self.timeout_id = None
def stop(self):
self.dot_widget.animation = NoAnimation(self.dot_widget)
if self.timeout_id is not None:
gobject.source_remove(self.timeout_id)
self.timeout_id = None
def stop(self):
self.dot_widget.animation = NoAnimation(self.dot_widget)
if self.timeout_id is not None:
gobject.source_remove(self.timeout_id)
self.timeout_id = None
def stop(self):
self.dot_widget.animation = NoAnimation(self.dot_widget)
if self.timeout_id is not None:
gobject.source_remove(self.timeout_id)
self.timeout_id = None
def _reset(self):
if self._find_child_hfp_modem:
try:
gobject.source_remove(self._poll_for_child_hfp_modem_id)
except:
pass
self._poll_for_child_hfp_modem_id = None
def stop_scrsaver(self):
"""stop screen saver"""
if self.scr_timer_id:
gobject.source_remove(self.scr_timer_id)
if self.video_playing:
self.movie_type = ''
self.video_playing = False
self.video_player.stop()
self.drwVideo.set_property('visible', False)
self.running = False
self.WinMain.hide_window('scrsaver')