Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer importing twisted.internet.reactor, fixes "reactor already installed" #93

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions server/recceiver/announce.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import struct

from twisted.internet import protocol, reactor
from twisted.internet import protocol
from twisted.logger import Logger

_log = Logger(__name__)
Expand All @@ -14,12 +14,14 @@
__all__ = ['Announcer']

class Announcer(protocol.DatagramProtocol):
reactor = reactor

def __init__(self, tcpport, key=0,
tcpaddr='\xff\xff\xff\xff',
udpaddrs=[('<broadcast>',5049)],
period=15.0):
from twisted.internet import reactor

self.reactor = reactor

if sys.version_info[0] < 3:
self.msg = _Ann.pack(0x5243, 0, tcpaddr, tcpport, 0, key)
else:
Expand Down
7 changes: 5 additions & 2 deletions server/recceiver/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from twisted import plugin
from twisted.python import usage, log
from twisted.internet import reactor, defer
from twisted.internet import defer
from twisted.internet.error import CannotListenError
from twisted.application import service
from twisted.logger import Logger
Expand All @@ -31,9 +31,12 @@ def flush(self):
pass

class RecService(service.MultiService):
reactor = reactor

def __init__(self, config):
from twisted.internet import reactor

self.reactor = reactor

service.MultiService.__init__(self)
self.annperiod = float(config.get('announceInterval', '15.0'))
self.tcptimeout = float(config.get('tcptimeout', '15.0'))
Expand Down
10 changes: 7 additions & 3 deletions server/recceiver/recast.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from twisted.protocols import stateful
from twisted.internet import defer
from twisted.internet import protocol
from twisted.internet import reactor

from .interfaces import ITransaction

Expand All @@ -38,11 +37,14 @@

class CastReceiver(stateful.StatefulProtocol):

reactor = reactor
timeout = 3.0
version = 0

def __init__(self, active=True):
from twisted.internet import reactor

self.reactor = reactor

self.sess, self.active = None, active
self.uploadSize, self.uploadStart = 0, 0

Expand Down Expand Up @@ -232,10 +234,12 @@ def __str__(self):
class CollectionSession(object):
timeout = 5.0
trlimit = 0
reactor = reactor

def __init__(self, proto, endpoint):
from twisted.internet import reactor

_log.info("Open session from {endpoint}",endpoint=endpoint)
self.reactor = reactor
self.proto, self.ep = proto, endpoint
self.TR = Transaction(self.ep, id(self))
self.TR.initial = True
Expand Down
4 changes: 3 additions & 1 deletion server/recceiver/udpbcast.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from twisted.internet import udp, reactor
from twisted.internet import udp
from twisted.application import internet

__all__ = ['SharedUDP','SharedUDPServer']
Expand Down Expand Up @@ -29,6 +29,8 @@ class SharedUDPServer(internet.UDPServer):
"""A UDP server using SharedUDP
"""
def _getPort(self):
from twisted.internet import reactor

R = getattr(self, 'reactor', reactor)
port = SharedUDP(reactor=R, *self.args, **self.kwargs)
port.startListening()
Expand Down
Loading