Ejemplo n.º 1
0
    def handleButtonClick():
        produce = [123, 456, 789, 012, 345, 678, 901]
        expect = dr.Struct(idx=0)

        def worker(a, b=None, sender=None):
            assert a == 2
            assert b == 'b'
            for val in produce:
                time.sleep(0.5)
                sender.sendResult(val)

        def consumer(result, b, a=None):
            assert b == 1
            assert a == 'a'
            result = result.get()
            print 'got result', result
            if expect.idx < len(produce):
                assert result == produce[
                    expect.idx]  #, 'Expected %s, got %s' % (
            else:
                assert result is None
                app.ExitMainLoop()
            expect.idx += 1

        dr.startWorker(consumer,
                       worker,
                       cargs=(1, ),
                       ckwargs={'a': 'a'},
                       wargs=(2, ),
                       wkwargs={'b': 'b'},
                       senderArg='sender')
Ejemplo n.º 2
0
def testAbort():
    import threading
    abort = dr.AbortEvent()
    
    # create a wx app and a function that will cause 
    # app to close when abort occurs
    app = wx.PySimpleApp()
    frame = wx.Frame(None) # need this otherwise MainLoop() returns immediately
    def exiter():
        abort.wait()
        # make sure any events have time to be processed before exit
        wx.FutureCall(2000, app.ExitMainLoop) 
    threading.Thread(target=exiter).start()

    # now do the delayed result computation:
    def worker():
        count = 0
        while not abort(1):
            print 'Result computation not done, not aborted'
        return 'Result computed'
    def consumer(dr): # never gets called but as example
        print 'Got dr=', dr.get()
        app.ExitMainLoop()
    dr.startWorker(consumer, worker)
    
    # pretend user doing other stuff
    import time
    time.sleep(5)
    # pretend user aborts now:
    print 'Setting abort event'
    abort.set()
    app.MainLoop()
Ejemplo n.º 3
0
 def handleButtonClick():
     dr.startWorker(frame,
                    worker,
                    cargs=(eventClass, ),
                    ckwargs={
                        'a': 'a',
                        'resultAttr': 'result'
                    },
                    wargs=(2, ),
                    wkwargs={'b': 'b'},
                    senderArg='sender')
Ejemplo n.º 4
0
 def handleButtonClick():
     produce = [123, 456, 789, 012, 345, 678, 901]
     expect = dr.Struct(idx=0)
     def worker(a, b=None, sender=None):
         assert a == 2
         assert b == 'b'
         for val in produce:
             time.sleep(0.5)
             sender.sendResult(val)
     def consumer(result, b, a=None):
         assert b == 1
         assert a=='a'
         result = result.get()
         print 'got result', result
         if expect.idx < len(produce):
             assert result == produce[ expect.idx ]#, 'Expected %s, got %s' % (
         else:
             assert result is None
             app.ExitMainLoop()
         expect.idx += 1
     
     dr.startWorker(consumer, worker, cargs=(1,), ckwargs={'a':'a'}, 
         wargs=(2,), wkwargs={'b':'b'}, senderArg='sender')
Ejemplo n.º 5
0
def testAbort():
    import threading
    abort = dr.AbortEvent()

    # create a wx app and a function that will cause
    # app to close when abort occurs
    app = wx.PySimpleApp()
    frame = wx.Frame(
        None)  # need this otherwise MainLoop() returns immediately

    def exiter():
        abort.wait()
        # make sure any events have time to be processed before exit
        wx.FutureCall(2000, app.ExitMainLoop)

    threading.Thread(target=exiter).start()

    # now do the delayed result computation:
    def worker():
        count = 0
        while not abort(1):
            print 'Result computation not done, not aborted'
        return 'Result computed'

    def consumer(dr):  # never gets called but as example
        print 'Got dr=', dr.get()
        app.ExitMainLoop()

    dr.startWorker(consumer, worker)

    # pretend user doing other stuff
    import time
    time.sleep(5)
    # pretend user aborts now:
    print 'Setting abort event'
    abort.set()
    app.MainLoop()
Ejemplo n.º 6
0
 def handleButtonClick():
     dr.startWorker(frame, worker, 
         cargs=(eventClass,), ckwargs={'a':'a','resultAttr':'result'}, 
         wargs=(2,), wkwargs={'b':'b'}, senderArg='sender')