| 320 | |
| 321 | def _no_reply_handler(*args): |
| 322 | pass |
| 323 | |
| 324 | def _notify_activity_ended_error_handler(err): |
| 325 | logging.error('Notify activity ended failed %s', err) |
| 326 | |
| 327 | def _child_watch_cb(self, pid, condition, user_data): |
| 328 | environment_dir, log_file = user_data |
| 329 | if environment_dir is not None: |
| 330 | subprocess.call(['/bin/rm', '-rf', environment_dir]) |
| 331 | try: |
| 332 | log_file.write('Activity died: pid %s condition %s data %s\n' % |
| 333 | (pid, condition, user_data)) |
| 334 | finally: |
| 335 | log_file.close() |
| 336 | |
| 337 | # try to reap zombies in case SIGCHLD has not been set to SIG_IGN |
| 338 | try: |
| 339 | os.waitpid(pid, 0) |
| 340 | except OSError: |
| 341 | # SIGCHLD = SIG_IGN, no zombies |
| 342 | pass |
| 343 | |
| 344 | self._shell.NotifyActivityEnded( |
| 345 | self._handle.activity_id, reply_handler=self._no_reply_handler, |
| 346 | error_handler=self._notify_activity_ended_error_handler) |
| 347 | |
| 348 | |
| 349 | def _child_watch_cb_stub(pid, condition, user_data): |
| 350 | # This stub function invokes the actual callback via gobject.idle_add |
| 351 | # to work around GIL related segfaults. See #1123 and #1147. |
| 352 | handler, environment_dir, log_file = user_data |
| 353 | gobject.idle_add(handler._child_watch_cb, pid, condition, |
| 354 | (environment_dir, log_file)) |
341 | | def _child_watch_cb(pid, condition, user_data): |
342 | | # FIXME we use standalone method here instead of ActivityCreationHandler's |
343 | | # member to have workaround code, see #1123 |
344 | | environment_dir, log_file = user_data |
345 | | if environment_dir is not None: |
346 | | subprocess.call(['/bin/rm', '-rf', environment_dir]) |
347 | | try: |
348 | | log_file.write('Activity died: pid %s condition %s data %s\n' % |
349 | | (pid, condition, user_data)) |
350 | | finally: |
351 | | log_file.close() |
352 | | |
353 | | # try to reap zombies in case SIGCHLD has not been set to SIG_IGN |
354 | | try: |
355 | | os.waitpid(pid, 0) |
356 | | except OSError: |
357 | | # SIGCHLD = SIG_IGN, no zombies |
358 | | pass |