当前位置: 首页>>代码示例>>Python>>正文


Python reactor.listenUNIX函数代码示例

本文整理汇总了Python中twisted.internet.reactor.listenUNIX函数的典型用法代码示例。如果您正苦于以下问题:Python listenUNIX函数的具体用法?Python listenUNIX怎么用?Python listenUNIX使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了listenUNIX函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: startSocketServer

def startSocketServer(root_node, shutdownOnLastDisconnect, interactive, socket=None, extra_loggers=None):
    """
    Bind the first available unix socket.
    Return the socket file.
    """
    # Create protocol factory.
    factory = Factory()
    factory.connectionPool = set()  # List of currently, active connections
    factory.protocol = CliClientProtocol
    factory.shutdownOnLastDisconnect = shutdownOnLastDisconnect
    factory.root_node = root_node
    factory.interactive = interactive
    factory.extra_loggers = extra_loggers or []
    factory.runtime_options = Options()

    # Listen on socket.
    if socket:
        reactor.listenUNIX(socket, factory)
    else:
        # Find a socket to listen on. (if no socket was given.)
        i = 0
        while True:
            try:
                socket = "/tmp/deployer.sock.%s.%i" % (getpass.getuser(), i)
                reactor.listenUNIX(socket, factory)
                break
            except CannotListenError:
                i += 1

                # When 100 times failed, cancel server
                if i == 100:
                    logging.warning("100 times failed to listen on posix socket. Please clean up old sockets.")
                    raise

    return socket
开发者ID:JeffreyVdb,项目名称:python-deployer,代码行数:35,代码来源:socket_server.py

示例2: daemon_main

     def daemon_main(self):
         if config.logreqs:
             self.logfile_access = logfile.DailyLogFile.fromFullPath(os.path.join(config.datadir, 'logs', 'access.log'))
         else:
             self.logfile_access = log.NullFile()

         if config.debugmode:
             if config.debugtostdout and config.nodaemon:
                 self.logfile_debug = sys.stdout
             else:
                 self.logfile_debug = logfile.DailyLogFile.fromFullPath(os.path.join(config.datadir, 'logs', 'debug.log'))
         else:
             self.logfile_debug = log.NullFile()

         log.startLogging(self.logfile_debug)

         reactor.listenTCPonExistingFD = listenTCPonExistingFD

         reactor.listenUNIX(os.path.join(config.rundir, 'rpc.socket'), factory=pb.PBServerFactory(self.rpc_server))

         for i in range(config.processes):
             subprocess = spawnT2W(self, self.childFDs, self.fds_https, self.fds_http)
             self.subprocesses.append(subprocess.pid)

         def MailException(etype, value, tb):
             sendexceptionmail(config, etype, value, tb)

         sys.excepthook = MailException

         reactor.run()
开发者ID:Acidburn0zzz,项目名称:Tor2web-3.0,代码行数:30,代码来源:t2w.py

示例3: run

    def run(self):
        self.factory = HTTPFactory(
            self.channel_layer,
            self.action_logger,
            timeout=self.http_timeout,
            websocket_timeout=self.websocket_timeout,
            ping_interval=self.ping_interval,
            ws_protocols=self.ws_protocols,
            root_path=self.root_path,
        )
        # Redirect the Twisted log to nowhere
        globalLogBeginner.beginLoggingTo([lambda _: None], redirectStandardIO=False, discardBuffer=True)
        # Listen on a socket
        if self.unix_socket:
            reactor.listenUNIX(self.unix_socket, self.factory)
        elif self.file_descriptor:
            # socket returns the same socket if supplied with a fileno
            sock = socket.socket(fileno=self.file_descriptor)
            reactor.adoptStreamPort(self.file_descriptor, sock.family, self.factory)
        else:
            reactor.listenTCP(self.port, self.factory, interface=self.host)

        if "twisted" in self.channel_layer.extensions:
            logging.info("Using native Twisted mode on channel layer")
            reactor.callLater(0, self.backend_reader_twisted)
        else:
            logging.info("Using busy-loop synchronous mode on channel layer")
            reactor.callLater(0, self.backend_reader_sync)
        reactor.callLater(2, self.timeout_checker)
        reactor.run(installSignalHandlers=self.signal_handlers)
开发者ID:bibinjose22,项目名称:daphne,代码行数:30,代码来源:server.py

示例4: test

def test():
    if stat.S_ISSOCK(os.fstat(fastcgi.FCGI_LISTENSOCK_FILENO)[stat.ST_MODE]):
        raise Exception('using pre-set fastcgi environment is not yet supported')
    
    fac = twistedfcgi.FastCGIFactory(handler)
    
    #reactor.listenTCP(8030, fac)
    reactor.listenUNIX('fcgi.socket', fac)
    reactor.run()
开发者ID:alexgirao,项目名称:fastcgi,代码行数:9,代码来源:fcgi-test3.py

示例5: run

def run():
  service = Place

  print("Start place_info Service")
  reactor.listenUNIX(PLACEINFO_UNIX_DOMAIN, PlaceInfoFactory(service))
  try:
    reactor.run()
  except Exception, err:
    logger.info(err)
开发者ID:tyrchen,项目名称:kagalaska,代码行数:9,代码来源:place_info.py

示例6: run

def run():
  service = TagRankService()

  print("Start relation Service")
  reactor.listenUNIX(RELATIONS_UNIX_DOMAIN, RelationFactory(service))
  try:
    reactor.run()
  except Exception, err:
    logger.info(err)
开发者ID:tyrchen,项目名称:kagalaska,代码行数:9,代码来源:relations.py

示例7: cbConnect

    def cbConnect(self, directoryService):
        """
        Callback from the directory service.

        From this point we're connected and authenticated.
        """
        basepath = FilePath(os.path.expanduser('~/.distfs'))
        if not basepath.exists():
            basepath.createDirectory()

        store = FileSystemStore(basepath.child('store').path)
        chunkFactory = Site(server.StoreResource(store))

        locname = self['alias'] or directoryService.service

        # Listen for remote connections.  This is for the other nodes
        # to access our store.
        port = self['port'] and int(self['port']) or 0
        listeningPort = reactor.listenTCP(port, chunkFactory)

        keyStore = SQLiteDataStore(basepath.child('%s.db' % locname).path)
        dhtNode = KademliaNode(listeningPort.getHost().port, keyStore,
                               reactor=reactor)
        
        # Listen locally so that applications can easily access the
        # store.
        reactor.listenUNIX(basepath.child('%s.http' % locname).path,
                           chunkFactory)

        resolverPublisher = ResolverPublisher(dhtNode)
        
        controlFactory = control.ControlFactory(store, directoryService,
                                                dhtNode, resolverPublisher)
        reactor.listenUNIX(basepath.child('%s.ctrl' % locname).path,
                           controlFactory)

        # Start a looping call that will publish chunks to the
        # overlay; do that every 6th hour.  Delay the procedure a bit
        # so that the node has a chance to join the network.
        looping = task.LoopingCall(publishChunks, store, resolverPublisher)
        reactor.callLater(10, looping.start, 6*60*60, True)

        # Try joining the network.
        introducers = list()
        if self['introducer']:
            try:
                address, port = self['introducer'].split(':')
            except ValueError:
                address, port = self['introducer'], 8033
            introducers.append((address, int(port)))
        dhtNode.joinNetwork(introducers)

        # At this point everything that can go (majorly) wrong has
        # been initialized and we can daemonize.
        if not self['no-daemon']:
            daemonize()
开发者ID:jrydberg,项目名称:distfs,代码行数:56,代码来源:script.py

示例8: __init__

 def __init__(self, command_cb, address = None, sock_owner = None):
     self.command_cb = command_cb
     self.protocol = Cli_session
     if address == None:
         address = '/var/run/ccm.sock'
     if exists(address):
         unlink(address)
     reactor.listenUNIX(address, self)
     if sock_owner != None:
         chown(address, sock_owner[0], sock_owner[1])
开发者ID:DarthRa,项目名称:pulsar,代码行数:10,代码来源:Cli_server_local.py

示例9: run

def run():
  wordseg = WordSegService()
  relations = TagService()

  print("Start WordSeg Service")
  reactor.listenUNIX(WORDSEG_UNIX_DOMAIN, WordSegFactory(wordseg, relations))
  try:
    reactor.run()
  except Exception, err:
    logger.info(err)
开发者ID:tyrchen,项目名称:kagalaska,代码行数:10,代码来源:tag_rank.py

示例10: autostart

def autostart(reason, **kwargs):
	if reason == 0:
		from twisted.internet import reactor
		try:
			os.remove("/tmp/hotplug.socket")
		except OSError:
			pass
		factory = Factory()
		factory.protocol = Hotplug
		reactor.listenUNIX("/tmp/hotplug.socket", factory)
开发者ID:dazulrich,项目名称:dvbapp,代码行数:10,代码来源:plugin.py

示例11: _run_manhole

    def _run_manhole(self):
        # This condition is made with the assumption that no existing daemon
        # is running. If there is one, the following code could potentially
        # cause problems for the other daemon by removing its socket.
        if os.path.exists(self.manhole_sock):
            log.info('Removing orphaned manhole socket')
            os.remove(self.manhole_sock)

        self.manhole = make_manhole(dict(trond=self, mcp=self.mcp))
        reactor.listenUNIX(self.manhole_sock, self.manhole)
        log.info(f"manhole started on {self.manhole_sock}")
开发者ID:Yelp,项目名称:Tron,代码行数:11,代码来源:trondaemon.py

示例12: run

    def run(self):
        """
        Start the server and listen on host:port
        """
        f = None
        unix_prefix = 'unix://'

        if self.http_enabled:
            rpc = JsonRpcHttpResource()
            rpc.rpcprocessor = self.rpcprocessor
            rpc.tls_client_auth_enabled = self.tls_client_auth_enabled

            if self.http_basic_auth_enabled:
                checker = PasswordChecker(self.passwdCheckFunction)
                realm = HttpPasswordRealm(rpc)
                p = portal.Portal(realm, [checker])

                realm_name = 'Reflect RPC'

                if sys.version_info.major == 2:
                    realm_name = realm_name.encode('utf-8')

                credentialFactory = BasicCredentialFactory(realm_name)
                rpc = HTTPAuthSessionWrapper(p, [credentialFactory])

            root = RootResource(rpc)

            f = server.Site(root)
        else:
            f = JsonRpcProtocolFactory(self.rpcprocessor,
                    self.tls_client_auth_enabled)

        if self.tls_enabled:
            if not self.tls_client_auth_enabled:
                reactor.listenSSL(self.port, f, self.cert.options(),
                        interface=self.host)
            else:
                reactor.listenSSL(self.port, f,
                        self.cert.options(self.client_auth_ca),
                        interface=self.host)
        else:
            if self.host.startswith(unix_prefix):
                path = self.host[len(unix_prefix):]
                reactor.listenUNIX(path, f, backlog=self.unix_socket_backlog,
                        mode=self.unix_socket_mode, wantPID=self.unix_socket_want_pid)
            else:
                reactor.listenTCP(self.port, f, interface=self.host)

        if self.host.startswith(unix_prefix):
            print("Listening on %s" % (self.host))
        else:
            print("Listening on %s:%d" % (self.host, self.port))

        reactor.run()
开发者ID:aheck,项目名称:reflectrpc,代码行数:54,代码来源:twistedserver.py

示例13: listen

	def listen(self):
		server = ModuleServer(self.options.module)

		# ensure that the UNIX socket is only accessable by root
		old_umask = umask(0077)
		try:
			reactor.listenUNIX(self.options.socket, server)
		finally:
			umask(old_umask)

		notifier.loop()
开发者ID:spaceone,项目名称:univention-management-console,代码行数:11,代码来源:daemon.py

示例14: main

def main():
    args = sys.argv[1: ]
    config = Config(args)
    comet_server = CometServer(config)
    site = server.Site(comet_server, timeout = config.http_timeout)
    if config.http_port != None:
        reactor.listenTCP(config.http_port, site)
        
    if config.unix_socket_path != None:
        reactor.listenUNIX(config.unix_socket_path, site)
        
    reactor.run()
开发者ID:carriercomm,项目名称:Simple-Comet-Server,代码行数:12,代码来源:simple_comet.py

示例15: autostart

def autostart(reason, **kwargs):
	if reason == 0:
		print "starting hotplug handler"
		factory = Factory()
		factory.protocol = Hotplug

		try:
			import os
			os.remove("/tmp/hotplug.socket")
		except OSError:
			pass

		reactor.listenUNIX("/tmp/hotplug.socket", factory)
开发者ID:FFTEAM,项目名称:enigma2-5,代码行数:13,代码来源:plugin.py


注:本文中的twisted.internet.reactor.listenUNIX函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。