Created
April 14, 2018 00:00
-
-
Save whalebot-helmsman/01c09721440edc428aef8d2cd5243daa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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