Dummy implementation of _thread.start_new_thread(). Compatibility is maintained by making sure that ``args`` is a tuple and ``kwargs`` is a dictionary. If an exception is raised and it is SystemExit (which can be done by _thread.exit()) it is caught and nothing is done; all other e
(function, args, kwargs={})
| 49 | |
| 50 | |
| 51 | def start_new_thread(function, args, kwargs={}): |
| 52 | """Dummy implementation of _thread.start_new_thread(). |
| 53 | |
| 54 | Compatibility is maintained by making sure that ``args`` is a |
| 55 | tuple and ``kwargs`` is a dictionary. If an exception is raised |
| 56 | and it is SystemExit (which can be done by _thread.exit()) it is |
| 57 | caught and nothing is done; all other exceptions are printed out |
| 58 | by using traceback.print_exc(). |
| 59 | |
| 60 | If the executed function calls interrupt_main the KeyboardInterrupt will be |
| 61 | raised when the function returns. |
| 62 | |
| 63 | """ |
| 64 | if type(args) != type(tuple()): |
| 65 | raise TypeError("2nd arg must be a tuple") |
| 66 | if type(kwargs) != type(dict()): |
| 67 | raise TypeError("3rd arg must be a dict") |
| 68 | global _main |
| 69 | _main = False |
| 70 | try: |
| 71 | function(*args, **kwargs) |
| 72 | except SystemExit: |
| 73 | pass |
| 74 | except: |
| 75 | import traceback |
| 76 | |
| 77 | traceback.print_exc() |
| 78 | _main = True |
| 79 | global _interrupt |
| 80 | if _interrupt: |
| 81 | _interrupt = False |
| 82 | raise KeyboardInterrupt |
| 83 | |
| 84 | |
| 85 | def start_joinable_thread(function, handle=None, daemon=True): |