Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Demo of button click handler:

.. code-block:: python

@engine.async
@engine.asynchronous
def on_button_click(self, *args):
self.status_label.setText("Downloading image...")
# Run single task in separate thread
Expand Down
2 changes: 1 addition & 1 deletion async_gui/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, pool_timeout=POOL_TIMEOUT):
#: main application instance
self.main_app = None

def async(self, func):
def asynchronous(self, func):
""" Decorator for asynchronous generators.

Any :class:`Task`, :class:`ProcessTask` or :class:`GTask` yielded from
Expand Down
3 changes: 3 additions & 0 deletions async_gui/toolkits/kivy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ def update_gui(self):
EventLoop.window._mainloop()
else:
EventLoop.idle()


engine = KivyEngine()
3 changes: 3 additions & 0 deletions async_gui/toolkits/pygtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ class GtkEngine(Engine):
def update_gui(self):
if gtk.events_pending():
gtk.main_iteration()


engine = GtkEngine()
5 changes: 4 additions & 1 deletion async_gui/toolkits/pyqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
class PyQtEngine(QtEngine):
""" PyQt4 support
"""
QtCore = QtCore
QtCore = QtCore


engine = PyQtEngine()
3 changes: 3 additions & 0 deletions async_gui/toolkits/tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ class TkEngine(Engine):
"""
def update_gui(self):
self.main_app.update()


engine = TkEngine()
3 changes: 3 additions & 0 deletions async_gui/toolkits/wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ class WxEngine(Engine):
"""
def update_gui(self):
self.main_app.Yield()


engine = WxEngine()
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ First create :class:`Engine` instance corresponding to your GUI toolkit (see

engine = PyQtEngine()

It contains decorator :meth:`@engine.async <Engine.async>` which allows you to
It contains decorator :meth:`@engine.asynchronous <Engine.asynchronous>` which allows you to
write asynchronous code in serial way without callbacks.
Example button click handler:

.. code-block:: python

@engine.async
@engine.asynchronous
def on_button_click(self, *args):
self.status_label.setText("Downloading image...")
# Run single task in separate thread
Expand Down
6 changes: 2 additions & 4 deletions examples/gtk_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import gtk

from async_gui import MultiProcessTask, Task
from async_gui.toolkits.pygtk import GtkEngine
from async_gui.toolkits.pygtk import engine
from examples.cpu_work import is_prime, PRIMES

engine = GtkEngine()


class GtkExample:
def __init__(self):
Expand All @@ -32,7 +30,7 @@ def __init__(self):
box.show()
self.window.show()

@engine.async
@engine.asynchronous
def check_primes(self, widget, data=None):
t = time.time()
self.status.set_label("Checking primes...")
Expand Down
6 changes: 2 additions & 4 deletions examples/kivy_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
import time

from async_gui.engine import Task, MultiProcessTask
from async_gui.toolkits.kivy import KivyEngine
from async_gui.toolkits.kivy import engine

from cpu_work import is_prime, PRIMES


engine = KivyEngine()

class MyApp(App):
def build(self):
grid = GridLayout(cols=4)
Expand All @@ -24,7 +22,7 @@ def build(self):
grid.add_widget(self.status)
return grid

@engine.async
@engine.asynchronous
def cpu_bound(self, *_):
t = time.time()
self.status.text = "calculating..."
Expand Down
9 changes: 3 additions & 6 deletions examples/qt_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@

from PyQt4 import QtGui
from async_gui.engine import Task
from async_gui.toolkits.pyqt import PyQtEngine
from async_gui.toolkits.pyqt import engine

if sys.version_info[0] == 3:
from urllib.request import urlopen
else:
from urllib import urlopen


engine = PyQtEngine()


class MainWidget(QtGui.QWidget):

def __init__(self, parent=None):
Expand All @@ -35,7 +32,7 @@ def __init__(self, parent=None):
layout.addWidget(self.result_label)
layout.addWidget(self.image_label)

@engine.async
@engine.asynchronous
def on_button_click(self, *args):
self.status_label.setText("Downloading image...")
# Run single task in separate thread
Expand All @@ -56,7 +53,7 @@ def on_button_click(self, *args):
def load_url(self, url):
return urlopen(url).read()

@engine.async
@engine.asynchronous
def check_primes(self, checked):
t = time.time()
self.status_label.setText("Checking primes...")
Expand Down
7 changes: 2 additions & 5 deletions examples/qt_app_unordered_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from async_gui import MultiTask
from async_gui.engine import Task
from async_gui.toolkits.pyqt import PyQtEngine
from async_gui.toolkits.pyqt import engine


if sys.version_info[0] == 3:
Expand All @@ -24,9 +24,6 @@
from urllib import urlopen


engine = PyQtEngine()


class MainWidget(QtGui.QWidget):

urls = [
Expand Down Expand Up @@ -74,7 +71,7 @@ def __init__(self, parent=None):
layout.addLayout(hbox)
layout.addWidget(self.urls_table)

@engine.async
@engine.asynchronous
def on_button_click(self, *args):
t = time.time()
self.status_label.setText("Downloading pages...")
Expand Down
7 changes: 2 additions & 5 deletions examples/tk_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
import time

from async_gui.engine import Task, MultiProcessTask
from async_gui.toolkits.tk import TkEngine
from async_gui.toolkits.tk import engine

from cpu_work import is_prime, PRIMES


engine = TkEngine()


class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master, width=800, height=400)
Expand All @@ -36,7 +33,7 @@ def __init__(self, master=None):
self.status.append(tk.Label(self))
self.status[i].grid(column=1, row=1 + i, sticky=tk.W)

@engine.async
@engine.asynchronous
def cpu_bound(self):
t = time.time()
self.status[0]["text"] = "calculating..."
Expand Down
8 changes: 2 additions & 6 deletions examples/wx_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
import time

import wx
from async_gui.toolkits.wx import WxEngine
from async_gui.toolkits.wx import engine
from async_gui.engine import Task, MultiProcessTask

from cpu_work import is_prime, PRIMES


engine = WxEngine()
async = engine.async


class Example(wx.Frame):

def __init__(self, parent, title):
Expand Down Expand Up @@ -43,7 +39,7 @@ def InitUI(self):
sizer.AddGrowableRow(2)
panel.SetSizerAndFit(sizer)

@engine.async
@engine.asynchronous
def cpu_bound(self, event):
t = time.time()
self.status.SetLabel("calculating...")
Expand Down
14 changes: 7 additions & 7 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


engine = Engine()
async = engine.async
asynchronous = engine.asynchronous


class EngineTestCase(unittest.TestCase):
Expand All @@ -35,7 +35,7 @@ def test_async(self):
def test_async_with_return_before_yield(self): # issue 1
called = [False]

@async
@asynchronous
def func():
called[0] = True
return
Expand All @@ -49,21 +49,21 @@ def shouldnt_call_this():
self.assertEquals(called[0], True)

def test_async_with_result(self):
@async
@asynchronous
def func():
r = yield self.Task(self.simple_method)
return_result(r)
self.assertEquals(func(), 42)

def test_async_process(self):
@async
@asynchronous
def func():
r = yield self.ProcessTask(mp_func, self._main_process)
return_result(r)
self.assertEquals(func(), 42)

def test_async_multiprocess(self):
@async
@asynchronous
def func():
n = 10
tasks = [self.ProcessTask(mp_func, self._main_process)
Expand All @@ -82,7 +82,7 @@ def func():
def test_multitask_unordered(self):
n = 100

@async
@asynchronous
def async_exec(tasks, skip_errors):
gen = yield self.MultiTask(tasks, unordered=True,
skip_errors=skip_errors)
Expand All @@ -97,7 +97,7 @@ def async_exec(tasks, skip_errors):
tasks.append(self.Task(self.throwing, "test"))
self.assertEquals(len(async_exec(tasks, skip_errors=True)), n + 1)

@async
@asynchronous
def async_method(self):
def check_the_same_thread():
return thread.get_ident() == self._main_thread
Expand Down
4 changes: 2 additions & 2 deletions tests/test_gevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
else:
patch_socket()
from async_gui.gevent_tasks import MultiGTask
from tests.test_engine import EngineTestCase, engine, async
from tests.test_engine import EngineTestCase, engine, asynchronous


class GeventExecutorTestCase(EngineTestCase):
Expand All @@ -25,7 +25,7 @@ class GeventExecutorTestCase(EngineTestCase):
def test_gevent_urllib(self):
self.gevent_with_urllib()

@async
@asynchronous
def gevent_with_urllib(self):

def download(url):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_toolkits.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def task_func(arg):
time.sleep(0.2) # timeout to let update_gui() be called
return arg

@engine.async
@engine.asynchronous
def async_gen():
answer = yield [Task(task_func, i) for i in range(N)]
self.assertEquals(answer, list(range(N)))
Expand Down