Run a function call as a background job (uses a separate thread).
| 466 | |
| 467 | |
| 468 | class BackgroundJobFunc(BackgroundJobBase): |
| 469 | """Run a function call as a background job (uses a separate thread).""" |
| 470 | |
| 471 | def __init__(self, func, *args, **kwargs): |
| 472 | """Create a new job from a callable object. |
| 473 | |
| 474 | Any positional arguments and keyword args given to this constructor |
| 475 | after the initial callable are passed directly to it.""" |
| 476 | |
| 477 | if not callable(func): |
| 478 | raise TypeError( |
| 479 | 'first argument to BackgroundJobFunc must be callable') |
| 480 | |
| 481 | self.func = func |
| 482 | self.args = args |
| 483 | self.kwargs = kwargs |
| 484 | # The string form will only include the function passed, because |
| 485 | # generating string representations of the arguments is a potentially |
| 486 | # _very_ expensive operation (e.g. with large arrays). |
| 487 | self.strform = str(func) |
| 488 | self._init() |
| 489 | |
| 490 | def call(self): |
| 491 | return self.func(*self.args, **self.kwargs) |
no outgoing calls
no test coverage detected
searching dependent graphs…