Ticket #1447: 0001-Notify-shell-when-activity-process-terminates.patch

File 0001-Notify-shell-when-activity-process-terminates.patch, 3.6 KB (added by wadeb, 15 years ago)

Update to GIL fix; remove debug prints

  • src/sugar/activity/activityfactory.py

    From 3af803a0e823bf552cb6178a9c63243e6e7933f3 Mon Sep 17 00:00:00 2001
    From: Wade Brainerd <wadetb@gmail.com>
    Date: Sun, 18 Oct 2009 07:57:38 -0400
    Subject: [PATCH] Notify shell when activity process terminates.
    
    Change _child_watch_cb to a global stub function which adds the real processing via _idle_add.  This works around what appears to be a Python GIL lock issue described in #1123 and #1447, reported upstream at https://bugs.freedesktop.org/show_bug.cgi?id=23507
    ---
     src/sugar/activity/activityfactory.py |   57 +++++++++++++++++++++-----------
     1 files changed, 37 insertions(+), 20 deletions(-)
    
    diff --git a/src/sugar/activity/activityfactory.py b/src/sugar/activity/activityfactory.py
    index ee0fd92..b0b70e9 100644
    a b class ActivityCreationHandler(gobject.GObject): 
    277277            stderr=log_file.fileno())
    278278
    279279        gobject.child_watch_add(child.pid,
    280                                 _child_watch_cb,
    281                                 (environment_dir, log_file))
     280                                _child_watch_cb_stub,
     281                                (self, environment_dir, log_file))
    282282
    283283    def _no_reply_handler(self, *args):
    284284        pass
    class ActivityCreationHandler(gobject.GObject): 
    317317    def _find_object_error_handler(self, err):
    318318        logging.error('Datastore find failed %s', err)
    319319        self._launch_activity()
     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
     349def _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))
    320355
    321356
    322357def create(bundle, activity_handle=None):
    def create_with_object_id(bundle, object_id): 
    338373    return ActivityCreationHandler(bundle, activity_handle)
    339374
    340375
    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