Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r824:861d54ea624e
Date: 2013-06-02 22:55 +0200
http://bitbucket.org/pypy/buildbot/changeset/861d54ea624e/

Log:    Call the handlers in a parallel thread, allowing the http request
        from bitbucket to get immediately an answer. (For tests, we don't
        use this parallel thread.)

diff --git a/bbhook/hook.py b/bbhook/hook.py
--- a/bbhook/hook.py
+++ b/bbhook/hook.py
@@ -3,6 +3,8 @@
 import subprocess
 import sys
 import time
+import thread, Queue
+import traceback
 
 from .main import app
 from . import scm
@@ -39,7 +41,24 @@
         yield commit
 
 
-def handle(payload, test=False):
+
+def _handle_thread():
+    while True:
+        local_repo = payload = None
+        try:
+            local_repo, payload = queue.get()
+            _do_handle(local_repo, payload)
+        except:
+            traceback.print_exc()
+            print >> sys.stderr, 'payload:'
+            pprint.pprint(payload, sys.stderr)
+            print >> sys.stderr
+
+queue = Queue.Queue()
+thread.start_new_thread(_handle_thread, ())
+
+
+def handle(payload, test=True):
     path = payload['repository']['absolute_url']
     owner = payload['repository']['owner']
     local_repo = app.config['LOCAL_REPOS'].join(path)
@@ -47,6 +66,12 @@
     if not check_for_local_repo(local_repo, remote_repo, owner):
         print >> sys.stderr, 'Ignoring unknown repo', path
         return
+    if test:
+        _do_handle(local_repo, payload, test)
+    else:
+        queue.put((local_repo, payload))
+
+def _do_handle(local_repo, payload, test=False):
     scm.hg('pull', '-R', local_repo)
     for commit in get_commits(payload):
         for handler in HANDLERS:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to