Merge lp:~mikemc/ubuntu-sso-client/fix-1017672-delayed-reaction-in-tcpactivation into lp:ubuntu-sso-client

Proposed by Mike McCracken on 2012-06-25
Status: Merged
Approved by: Manuel de la Peña on 2012-06-26
Approved revision: 977
Merged at revision: 977
Proposed branch: lp:~mikemc/ubuntu-sso-client/fix-1017672-delayed-reaction-in-tcpactivation
Merge into: lp:ubuntu-sso-client
Diff against target: 85 lines (+10/-5)
2 files modified
ubuntu_sso/utils/tcpactivation.py (+3/-1)
ubuntu_sso/utils/tests/test_tcpactivation.py (+7/-4)
To merge this branch: bzr merge lp:~mikemc/ubuntu-sso-client/fix-1017672-delayed-reaction-in-tcpactivation
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve on 2012-06-26
Brian Curtin (community) 2012-06-25 Approve on 2012-06-25
Review via email: mp+111945@code.launchpad.net

Commit Message

- delay importing twisted.internet.reactor to avoid creating default reactor when we need qt4reactor ( lp #1017672 )

Description of the Change

- delay importing twisted.internet.reactor to avoid creating default reactor when we need qt4reactor ( lp #1017672 )

on darwin and windows, we need the qt4reactor to be installed, but only after the QApplication is initialized. however, UniqueApplication eventually imports tcpactivation, which imports twisted.internet.reactor, creating a default reactor instead of the qt4reactor.

Here we delay the import to the functions that use 'reactor' to avoid its undesirable side effect.

To post a comment you must log in.
review: Approve
Manuel de la Peña (mandel) wrote :

I'm got a feeling that this was due to my tcpactivation changes, good catch! but lint does not like you :(

ubuntu_sso/utils/tests/test_tcpactivation.py:
    438: [W0621, server_test] Redefining name 'reactor' from outer scope (line 39)
    473: [W0621, client_test] Redefining name 'reactor' from outer scope (line 39)
    39: [W0611] Unused import reactor

review: Needs Fixing
977. By Mike McCracken on 2012-06-26

remove unused reactor import at top

Manuel de la Peña (mandel) wrote :

Passes in all platforms!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/utils/tcpactivation.py'
2--- ubuntu_sso/utils/tcpactivation.py 2012-06-08 12:01:37 +0000
3+++ ubuntu_sso/utils/tcpactivation.py 2012-06-26 15:51:17 +0000
4@@ -30,7 +30,7 @@
5
6 import subprocess
7
8-from twisted.internet import defer, error, protocol, reactor
9+from twisted.internet import defer, error, protocol
10 from twisted.internet.endpoints import clientFromString
11
12 LOCALHOST = "127.0.0.1"
13@@ -43,6 +43,7 @@
14
15 def async_sleep(delay):
16 """Fire the returned deferred after some specified delay."""
17+ from twisted.internet import reactor
18 d = defer.Deferred()
19 # pylint: disable=E1101
20 reactor.callLater(delay, d.callback, None)
21@@ -118,6 +119,7 @@
22 @defer.inlineCallbacks
23 def is_already_running(self):
24 """Check if the instance is already running."""
25+ from twisted.internet import reactor
26 factory = PortDetectFactory()
27 client = clientFromString(reactor, self.config.description.client)
28 try:
29
30=== modified file 'ubuntu_sso/utils/tests/test_tcpactivation.py'
31--- ubuntu_sso/utils/tests/test_tcpactivation.py 2012-06-19 16:14:01 +0000
32+++ ubuntu_sso/utils/tests/test_tcpactivation.py 2012-06-26 15:51:17 +0000
33@@ -35,7 +35,8 @@
34 # this test module access a few protected members (starting with _)
35 # pylint: disable=W0212
36
37-from twisted.internet import defer, protocol, reactor, task
38+import twisted.internet
39+from twisted.internet import defer, protocol, task
40 from twisted.trial.unittest import TestCase
41
42 # pylint: disable=W0611
43@@ -106,7 +107,7 @@
44 yield super(AsyncSleepTestCase, self).setUp()
45 self.test_timeout = 5.0
46 self.clock = task.Clock()
47- self.patch(tcpactivation, "reactor", self.clock)
48+ self.patch(twisted.internet, "reactor", self.clock)
49 self.d = tcpactivation.async_sleep(self.test_timeout)
50
51 def test_async_sleep_not_fired_immediately(self):
52@@ -330,7 +331,7 @@
53 """Test the _wait_server_active method."""
54 ac = ActivationClient(self.config)
55 clock = task.Clock()
56- self.patch(tcpactivation, "reactor", clock)
57+ self.patch(twisted.internet, "reactor", clock)
58 self.patch(ac, "is_already_running", lambda: defer.succeed(False))
59
60 d = ac._wait_server_active()
61@@ -346,7 +347,7 @@
62 """If the server takes too long to start then timeout."""
63 ac = ActivationClient(self.config)
64 clock = task.Clock()
65- self.patch(tcpactivation, "reactor", clock)
66+ self.patch(twisted.internet, "reactor", clock)
67 self.patch(ac, "is_already_running", lambda: defer.succeed(False))
68 d = ac._wait_server_active()
69 clock.pump([tcpactivation.DELAY_BETWEEN_CHECKS] *
70@@ -434,6 +435,7 @@
71
72 def server_test(config):
73 """An IRL test of the server."""
74+ from twisted.internet import reactor
75
76 def got_description(description):
77 """The description was found."""
78@@ -468,6 +470,7 @@
79
80 def client_test(config):
81 """An IRL test of the client."""
82+ from twisted.internet import reactor
83 print "starting the client."
84 ac = ActivationClient(config)
85 d = ac.get_active_client_description()

Subscribers

People subscribed via source and target branches