(target)
| 82 | |
| 83 | @wraps(target) |
| 84 | def main_task(target): |
| 85 | try: |
| 86 | target() |
| 87 | except Exception as e: |
| 88 | if not isinstance(e, SessionException): |
| 89 | self.on_task_exception() |
| 90 | finally: |
| 91 | for t in self.threads: |
| 92 | if t.is_alive() and t is not threading.current_thread(): |
| 93 | t.join() |
| 94 | |
| 95 | try: |
| 96 | if self.need_keep_alive(): |
| 97 | from ..session import hold |
| 98 | hold() |
| 99 | else: |
| 100 | self.send_task_command(dict(command='close_session')) |
| 101 | except SessionException: # ignore SessionException error |
| 102 | pass |
| 103 | finally: |
| 104 | # we need first trigger close event and then perform close operation, |
| 105 | # because close operation will clean up all resources in this session, |
| 106 | # which may need to be accessed in close event |
| 107 | self._trigger_close_event() |
| 108 | self.close() |
| 109 | |
| 110 | thread = threading.Thread(target=main_task, kwargs=dict(target=target), |
| 111 | daemon=True, name='main_task') |
nothing calls this directly
no test coverage detected