Skip to content

Instantly share code, notes, and snippets.

@whalebot-helmsman
Created April 14, 2018 00:00
Show Gist options
  • Save whalebot-helmsman/01c09721440edc428aef8d2cd5243daa to your computer and use it in GitHub Desktop.
Save whalebot-helmsman/01c09721440edc428aef8d2cd5243daa to your computer and use it in GitHub Desktop.
import multiprocessing
import twisted.web.http
import twisted.internet
def run_mock(q):
factory = twisted.web.http.HTTPFactory()
port = twisted.internet.reactor.listenTCP(0, factory)
def report_host():
httpHost = port.getHost()
address = "http://%s:%d" % (httpHost.host, httpHost.port)
q.put(address)
twisted.internet.reactor.callWhenRunning(report_host)
twisted.internet.reactor.run()
def main():
q = multiprocessing.Queue()
p = multiprocessing.Process(target=run_mock, args=(q, ))
p.start()
address = q.get()
print('Serve on %s' % (address, ))
p.join()
q.close()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment