Runs the given function in a background thread. Note: The function is executed in a "fire and forget" manner. Args: function: The function to be executed in a thread. args: Optional `function` arguments as a tuple.
(function, args=None)
| 94 | |
| 95 | |
| 96 | def background_thread(function, args=None): |
| 97 | """Runs the given function in a background thread. |
| 98 | |
| 99 | Note: The function is executed in a "fire and forget" manner. |
| 100 | |
| 101 | Args: |
| 102 | function: The function to be executed in a thread. |
| 103 | args: Optional `function` arguments as a tuple. |
| 104 | """ |
| 105 | # Never wait or join a regular thread because it will block the SocketIO |
| 106 | # server: |
| 107 | # https://github.com/miguelgrinberg/Flask-SocketIO/issues/1264#issuecomment-620653614 |
| 108 | thread = threading.Thread(target=function, args=args or ()) |
| 109 | thread.start() |