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 554501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:42:59+00:00 2026-05-13T11:42:59+00:00

I want to use twisted (and StarPy which is a protocol implementation for asterisk

  • 0

I want to use twisted (and StarPy which is a protocol implementation for asterisk ami) to connect to an asterisk server. The application initiates a outgoing fax there. I found some hints on my problem, but I cannot find out how to handle this correctly.

The first fax is sent out correctly.

Problem is, if I call twisted for the
second time, the application keeps
hanging in main loop.

I know I may NOT do this like here:

from starpy import manager
from twisted.internet import reactor

def main():
    f = manager.AMIFactory(cUser, cPass)
    print "Login"
    df = f.login(cServer, cPort)

    def onLogin(protocol):
        print "Logoff again"
        df = protocol.logoff()

        def onLogoff( result ):
            print "Logoff erfolgt"
            reactor.stop()

        return df.addCallbacks( onLogoff, onLogoff )

    def onFailure( reason ):
        print "Login failed"
        print reason.getTraceback()

    df.addCallbacks( onLogin, onFailure )
    return df

if __name__ == "__main__":
    reactor.callWhenRunning( main )
    reactor.run(installSignalHandlers=0)
    print "runned the first time"

    reactor.callWhenRunning( main )
    reactor.run(installSignalHandlers=0)
    print "will never reach this point"

I simplified the code – it does nothing than login + logoff again. It will never return from the second reactor.run() call.

How is this done correctly? I’m stuck here – thanks in advance.

Best Regards,
Florian.

  • 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-13T11:43:00+00:00Added an answer on May 13, 2026 at 11:43 am

    Thanks for your answers, I haven’t implemented a solution right now but I know how I could do that now…

    Here a short summary of things I learned.

    First, in short – the problems I had with twisted:

    1. I didn’t understand the asynchronous basics of twisted. I used something like that in gui-frameworks but didn’t see the benefit for a long time.
    2. Second, I tried to think of an synchronous call of the event loop multiple times. This was necessary in my mind because I may not use more than one outgoing fax line at a time. Because the event loop of twisted is not restartable this is no option. As I could read in the docs “deferToThread” could help me here, but I think it’s not the best solution.

    In my concept I solved these problems:

    • Use of defer.DeferredSemaphore() which allows me to limit concurrency to 1.
      I found an example here: http://oubiwann.blogspot.com/2008/06/async-batching-with-twisted-walkthrough.html
    • calling twisted anynchronously and let the Defereds do the work (send a fax)
    • Writing the fax status to the database and sending the receipt mail is called from the defereds

    I needed a lot of re-thinking but as soon as you get it it looks really easy.

    Thanks to iny and Jean-Paul Calderone for your help.

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

Sidebar

Ask A Question

Stats

  • Questions 292k
  • Answers 292k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Simple assignment to simple variables is "atomic" AKA threadsafe (compound… May 13, 2026 at 6:08 pm
  • Editorial Team
    Editorial Team added an answer The best and typical way is to add this to… May 13, 2026 at 6:08 pm
  • Editorial Team
    Editorial Team added an answer Yes, it does. See http://msdn.microsoft.com/en-us/library/aa664754(VS.71).aspx and how LinkedList enumerator respects… May 13, 2026 at 6:08 pm

Related Questions

I wrote an application server (using python & twisted) and I want to start
In short I'm creating a Flash based multiplayer game and I'm now starting to
I want to put together simple TCP server using Python and Twisted. The server
I'm attempting to use the Repository Pattern to write a data access layer on
All I want to do is make some RPC calls over sockets. I have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.