Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4083988
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:22:58+00:00 2026-05-20T18:22:58+00:00

I have a jabber client that is reading from its stdin and posting PubSub

  • 0

I have a jabber client that is reading from its stdin and posting PubSub messages. If I get EOF on stdin, I want to terminate the client.

I first tried sys.exit(), but this causes an exception and the client does not exit. I then did some searching and found out that I should call reactor.stop(), but I am unable to make this work. The following code in my client:

from twisted.internet import reactor
reactor.stop()

Results in exceptions.AttributeError: 'module' object has no attribute 'stop'

What do I need to do to cause twistd to shut my application down and exit?

EDIT 2

The original problem was caused by some symlinks messing up the module import. After fixing that problem, I get a new exception:

twisted.internet.error.ReactorNotRunning: Can't stop reactor that isn't running.

After the exception, twistd shuts down. I think this may be caused by the call to MyClient.loop in MyClient.connectionInitialized. Perhaps I need to defer the call until later?

EDIT

Here’s the .tac file for my client

import sys

from twisted.application import service
from twisted.words.protocols.jabber.jid import JID

from myApp.clients import MyClient

clientJID = JID('client@example.com')
serverJID = JID('pubsub.example.com')
password = 'secret'

application = service.Application('XMPP client')
xmppClient = client.XMPPClient(clientJID, password)
xmppClient.logTraffic = True
xmppClient.setServiceParent(application)

handler = MyClient(clientJID, serverJID, sys.stdin)
handler.setHandlerParent(xmppClient)

Which I’m invoking with

twistd -noy sentry/myclient.tac < input.txt

Here’s the code for MyClient:

import os
import sys
import time
from datetime import datetime

from wokkel.pubsub import PubSubClient

class MyClient(PubSubClient):
    def __init__(self, entity, server, file, sender=None):
        self.entity = entity
        self.server = server
        self.sender = sender
        self.file = file

    def loop(self):
        while True:
            line = self.file.readline()
            if line:
                print line
            else:
                from twisted.internet import reactor
                reactor.stop()

    def connectionInitialized(self):
        self.loop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:22:59+00:00Added an answer on May 20, 2026 at 6:22 pm
    from twisted.internet import reactor
    reactor.stop()
    

    that should work. The fact that it doesn’t means something else is wrong on your application. I can’t figure out what’s wrong from the information you provided.

    Can you provide more (all) of the code?


    EDIT:

    Ok, now the problem is that you don’t stop your own while True loop, so it will keep looping and eventually stop the reactor again.

    Try this:

    from twisted.internet import reactor
    reactor.stop()
    return
    

    Now, I suspect your loop isn’t very good thing for a event-driven framework. While you’re just printing lines, it is fine, but depending on what you want to really do (I suspect you’ll do more than just print lines) you’ll have to refactor that loop to work with events.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we're have a client that needs to get interactive messages from a server, from
I have the following XML: <iq xmlns=jabber:client to=39850777771287777738178727@guest.google.com/agsXMPP xml:lang=en id=sub23 from=search.google.com type=result> <pubsub xmlns=http://jabber.org/protocol/pubsub>
I have a script that listens to a jabber server and responds accordingly. Though
I am trying to write an xmpp client to send/recieve messages from gtalk. Before
I have a application im working on that uses the Jabber Libraries to connect
I have two questions : I have a jabber client developed with Xcode in
I have default FOSUserBundle registration form. I want to add jabber field into registration
I have created a jabberbot class that I would like to broadcast scheduled messages.
I am generating messages like this $msg({to: 'user', from: 'me', type: 'chat'}).c(body).t('some data'); that
I have a custom Jabber IM client and I'm having a problem with links.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.