Skip to content
Snippets Groups Projects
Commit 0deb8e7d authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Bugfix in async.idle handling of alwaysQueue option. New function idleReset,

which is primarily for testing.
parent ba57f116
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,7 @@ Idle tasks ...@@ -23,6 +23,7 @@ Idle tasks
idleWhen idleWhen
inIdle inIdle
cancelIdle cancelIdle
idleReset
getIdleTimeout getIdleTimeout
setIdleTimeout setIdleTimeout
...@@ -202,6 +203,29 @@ _idleCallRate = 200 ...@@ -202,6 +203,29 @@ _idleCallRate = 200
""" """
def idleReset():
"""Reset the internal :func:`idle` queue state.
In a normal execution environment, this function will never need to be
called. However, in an execution environment where multiple ``wx.App``
instances are created, run, and destroyed sequentially, this function
will need to be called after each ``wx.App`` has been destroyed.
Otherwise the ``idle`` function will not work during exeution of
subsequent ``wx.App`` instances.
"""
global _idleRegistered
global _idleQueue
global _idleQueueDict
global _idleTimer
global _idleCallRate
_idleRegistered = False
_idleQueue = queue.Queue()
_idleQueueDict = {}
_idleTimer = None
_idleCallRate = 200
def getIdleTimeout(): def getIdleTimeout():
"""Returns the current ``wx`` idle loop time out/call rate. """Returns the current ``wx`` idle loop time out/call rate.
""" """
...@@ -373,7 +397,9 @@ def idle(task, *args, **kwargs): ...@@ -373,7 +397,9 @@ def idle(task, *args, **kwargs):
argument. If ``True``, and a ``wx.MainLoop`` is not argument. If ``True``, and a ``wx.MainLoop`` is not
running, the task is enqueued anyway, under the running, the task is enqueued anyway, under the
assumption that a ``wx.MainLoop`` will be started in assumption that a ``wx.MainLoop`` will be started in
the future. the future. Note that another call to ``idle`` must
be made after the ``MainLoop`` has started for the
original task to be executed.
All other arguments are passed through to the task function. All other arguments are passed through to the task function.
...@@ -413,10 +439,12 @@ def idle(task, *args, **kwargs): ...@@ -413,10 +439,12 @@ def idle(task, *args, **kwargs):
skipIfQueued = kwargs.pop('skipIfQueued', False) skipIfQueued = kwargs.pop('skipIfQueued', False)
alwaysQueue = kwargs.pop('alwaysQueue', False) alwaysQueue = kwargs.pop('alwaysQueue', False)
if alwaysQueue or _haveWX(): havewx = _haveWX()
if havewx or alwaysQueue:
import wx import wx
if not _idleRegistered: if havewx and (not _idleRegistered):
app = wx.GetApp() app = wx.GetApp()
app.Bind(wx.EVT_IDLE, _wxIdleLoop) app.Bind(wx.EVT_IDLE, _wxIdleLoop)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment