Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

import threading 

from gi.repository import GLib 

 

from lutris.util.log import logger 

 

 

def async_call(func, on_done, *args, **kwargs): 

    """ Launch given function `func` in a new thread """ 

    logger.debug("Async call: %s", str(func.__name__)) 

    if not on_done: 

        on_done = lambda r, e: None 

 

    def do_call(*args, **kwargs): 

        result = None 

        error = None 

 

        try: 

            result = func(*args, **kwargs) 

        except Exception, err: 

            logger.error("Error while completing task %s: %s", func, err) 

            #raise  # Uncomment this to inspect errors 

            error = err 

        GLib.idle_add(lambda: on_done(result, error)) 

 

    thread = threading.Thread(target=do_call, args=args, kwargs=kwargs) 

    thread.start()