Total Complexity | 4 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | """ |
||
13 | class SIGCHLDEventHandler: |
||
14 | """ |
||
15 | An event handler when SIGCHLD has been received. |
||
16 | """ |
||
17 | |||
18 | # ------------------------------------------------------------------------------------------------------------------ |
||
19 | @staticmethod |
||
20 | def handle(_event, _event_data, spawner): |
||
21 | """ |
||
22 | Handles an exit of a child and ends a job handler. |
||
23 | |||
24 | :param * _event: Not used. |
||
25 | :param * _event_data: Not used. |
||
26 | :param enarksh.spawner.Spawner.Spawner spawner: The spawner. |
||
27 | """ |
||
28 | del _event, _event_data |
||
29 | |||
30 | try: |
||
31 | pid = -1 |
||
32 | while pid != 0: |
||
33 | pid, status = os.waitpid(-1, os.WNOHANG + os.WUNTRACED + os.WCONTINUED) |
||
34 | if pid != 0: |
||
35 | job_handler = spawner.job_handlers[pid] |
||
36 | |||
37 | # Send message to controller that a job has finished. |
||
38 | message = JobFinishedMessage(job_handler.sch_id, job_handler.rnd_id, status) |
||
39 | message.send_message('controller') |
||
40 | |||
41 | # Inform the job handler the job has finished. |
||
42 | job_handler.set_job_has_finished() |
||
43 | except OSError: |
||
44 | # Ignore OSError. No more children to wait for. |
||
45 | pass |
||
46 | |||
48 |