Naftuli Kay
Naftuli Kay

Reputation: 91620

How to catch exceptions in twisted?

I'm running a pretty simple server in Python using Twisted. When I try to run two at the same time, this exception occurs:

twisted.internet.error.CannotListenError: Couldn't listen on 127.0.0.1:5050: [Errno 98] Address already in use.

It makes a lot of sense. How can I catch this exception?

I'd simply like to terminate the reactor and shut everything down if an existing server is running. Otherwise, I get the exception and it just hangs indefinitely until I kill the process.

Upvotes: 2

Views: 5111

Answers (1)

ben w
ben w

Reputation: 2535

You need to use an error handler callback, an errBack in Twisted lingo. You can add one to a Deferred using the addErrback method.

Upvotes: 7

Related Questions