Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
diff options
context:
space:
mode:
authorWade Brainerd <wadetb@gmail.com>2008-05-08 09:23:13 (GMT)
committer Wade Brainerd <wadetb@gmail.com>2008-05-08 09:23:13 (GMT)
commit2b6d6694259e024dc05112d25e1b9160f5d013cb (patch)
treea2364a4d682ff5ed9a8120e070eeb6dc1cb956fa /activity.py
parentfeb6d1b9f8f7350436106e3b071301f4bf16b47e (diff)
The server gets killed now when the activity exits, but an occasional race condition persists where the server fails to start before the first page is requested.
Diffstat (limited to 'activity.py')
-rw-r--r--activity.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/activity.py b/activity.py
index 3cf7db0..a3932a6 100644
--- a/activity.py
+++ b/activity.py
@@ -1,11 +1,12 @@
import os
import sys
+import signal
+import atexit
-# Import the WebActivity class from the Web activity directory.
from sugar.activity import registry
activity_info = registry.get_registry().get_activity('org.laptop.WebActivity')
-sys.path.append(activity_info.path)
+sys.path.append(activity_info.path)
import webactivity
# Default settings.
@@ -16,9 +17,19 @@ HOME_PAGE = '/wiki/Peru'
# Activity class, extends WebActivity.
class WikipediaActivity(webactivity.WebActivity):
def __init__(self, handle):
+
+ print "Starting server...\n"
+
+ os.chdir(os.environ['SUGAR_BUNDLE_PATH'])
+ self.server_pid = os.spawnlp(os.P_NOWAIT, 'python', 'python', 'py/server.py', WIKIDB, HTTP_PORT)
+
+ atexit.register(self.kill_server)
+
handle.uri = 'http://localhost:%s%s' % (HTTP_PORT, HOME_PAGE)
webactivity.WebActivity.__init__(self, handle)
-
- os.chdir(os.environ['SUGAR_BUNDLE_PATH'])
- os.spawnlp(os.P_NOWAIT, 'python', 'python', 'py/server.py', WIKIDB, HTTP_PORT)
+
+ def kill_server(self):
+ print "Stopping server...\n"
+ os.kill(self.server_pid, signal.SIGHUP)
+ \ No newline at end of file