<div dir="ltr">Hi everyone, <br><br>I'm writing a client library that makes (potentially long running) HTTP requests. Since the library will be used within non-Twisted code, I was thinking of running the reactor in a separate thread. The library code looks roughly like this:<br>

<br>def start():<br>    Thread(target=reactor.run, args=(False,)).start()<br><br>def shutdown():<br>    reactor.callFromThread(lambda x: reactor.stop(), None)<br><br>def make_request(url):<br>        agent = Agent(reactor)<br>

        d = agent.request(<br>            'GET',<br>            url,<br>            Headers({<br>                'User-Agent': ['Twisted SSE Client'],<br>                'Cache-Control': ['no-cache'],<br>
            }),<br>            None)<br>        d.addCallback(self.cbRequest)<br><br>Then I make requests from the application like so:<br><br>start()<br>make_request("<a href="http://localhost:12000" target="_blank">http://localhost:12000</a>")<br>

....<br>make_request("<a href="http://localhost:12000" target="_blank">http://localhost:12000</a>")<br>...<br>shutdown()<br><br>However, it looks like the 'd' deferred never gets fired. From a little playing around, it looks like this is because the reactor is started before the call(s) to agent.request are made. All examples in the twisted docs create the request before running the reactor. I'm sure I'm missing something very obvious here. Also, is there a better way to design such a library?<br clear="all">

<br>-- <br>-Ameya
</div>