Few of Twisted's APIs will succeed without a running reactor. The reactor is responsible for doing the I/O. You must have a running reactor in order to set up a connection (regardless of whether you are using an endpoint object or some other API to do so).
As far as I can tell, the pyglet integration reactor does not automatically start itself. Something must call its run
method. Your question suggests that you are not calling it, so I'm quite curious what is calling it.
When I modify your example to make it complete and runnable and add error reporting, like this:
from pygletreactor import install
install()
from twisted.internet import reactor
from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.internet.protocol import Factory
from twisted.protocols.amp import AMP
from twisted.python.log import err
def connect():
endpoint = TCP4ClientEndpoint(reactor, "127.0.0.1", 8750)
factory = Factory()
factory.protocol = AMP
return endpoint.connect(factory)
d = connect()
def connected(protocol):
return protocol.callRemote(
RegisterUser,
username=u'alice')
d.addCallback(connected)
d.addErrback(err)
reactor.run()
Then I get the behavior I expect, which is for the connection to be attempted and then fail (because I am not running an AMP server anywhere):
Unhandled Error
Traceback (most recent call last):
Failure: twisted.internet.error.ConnectionRefusedError: Connection was refused by other side: 111: Connection refused.
Perhaps you can compare this to your complete program and find an important difference.