Avoid importing twisted.internet.reactor in global scope
This import has side effects, which can cause problems when using a non- default reactor (qt5reactor, for example).
This commit is contained in:
parent
c198117980
commit
4a2f3baf28
|
@ -10,8 +10,9 @@ from collections import deque
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from nacl.secret import SecretBox
|
from nacl.secret import SecretBox
|
||||||
|
import twisted.internet
|
||||||
from twisted.internet import (address, defer, endpoints, error, interfaces,
|
from twisted.internet import (address, defer, endpoints, error, interfaces,
|
||||||
protocol, reactor, task)
|
protocol, task)
|
||||||
from twisted.internet.defer import inlineCallbacks, returnValue
|
from twisted.internet.defer import inlineCallbacks, returnValue
|
||||||
from twisted.protocols import policies
|
from twisted.protocols import policies
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
|
@ -559,7 +560,7 @@ class Common:
|
||||||
transit_relay,
|
transit_relay,
|
||||||
no_listen=False,
|
no_listen=False,
|
||||||
tor=None,
|
tor=None,
|
||||||
reactor=reactor,
|
reactor=None,
|
||||||
timing=None):
|
timing=None):
|
||||||
self._side = bytes_to_hexstr(os.urandom(8)) # unicode
|
self._side = bytes_to_hexstr(os.urandom(8)) # unicode
|
||||||
if transit_relay:
|
if transit_relay:
|
||||||
|
@ -579,6 +580,8 @@ class Common:
|
||||||
self._waiting_for_transit_key = []
|
self._waiting_for_transit_key = []
|
||||||
self._listener = None
|
self._listener = None
|
||||||
self._winner = None
|
self._winner = None
|
||||||
|
if reactor is None:
|
||||||
|
reactor = twisted.internet.reactor
|
||||||
self._reactor = reactor
|
self._reactor = reactor
|
||||||
self._timing = timing or DebugTiming()
|
self._timing = timing or DebugTiming()
|
||||||
self._timing.add("transit")
|
self._timing.add("transit")
|
||||||
|
@ -596,7 +599,7 @@ class Common:
|
||||||
direct_hints = [
|
direct_hints = [
|
||||||
DirectTCPV1Hint(six.u(addr), portnum, 0.0) for addr in addresses
|
DirectTCPV1Hint(six.u(addr), portnum, 0.0) for addr in addresses
|
||||||
]
|
]
|
||||||
ep = endpoints.serverFromString(reactor, "tcp:%d" % portnum)
|
ep = endpoints.serverFromString(twisted.internet.reactor, "tcp:%d" % portnum)
|
||||||
return direct_hints, ep
|
return direct_hints, ep
|
||||||
|
|
||||||
def get_connection_abilities(self):
|
def get_connection_abilities(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user