Skip to content

Commit

Permalink
use create_server tulip api
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Oct 10, 2013
1 parent c8d6e01 commit 8061d03
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
11 changes: 5 additions & 6 deletions asynchttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,15 @@ def run(loop, fut):
thread_loop = tulip.new_event_loop()
tulip.set_event_loop(thread_loop)

socks = thread_loop.run_until_complete(
thread_loop.start_serving(
server = thread_loop.run_until_complete(
thread_loop.create_server(
lambda: TestHttpServer(keep_alive=0.5),
host, port, ssl=sslcontext))

waiter = tulip.Future(loop=thread_loop)
loop.call_soon_threadsafe(
fut.set_result, (thread_loop, waiter, socks[0].getsockname()))
fut.set_result, (thread_loop, waiter,
server.sockets[0].getsockname()))

try:
thread_loop.run_until_complete(waiter)
Expand All @@ -125,9 +126,7 @@ def run(loop, fut):

run_briefly(thread_loop) # call close callbacks

for s in socks:
thread_loop.stop_serving(s)

server.close()
thread_loop.stop()
thread_loop.close()
gc.collect()
Expand Down
8 changes: 6 additions & 2 deletions asynchttp/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ def factory(self):

@tulip.coroutine
def _run(self):
for sock in self.sockets:
tulip.async(self.loop.start_serving(self.factory, sock=sock.sock))
servers = [
self.loop.create_server(self.factory, sock=sock.sock)
for sock in self.sockets]

# If our parent changed then we shut down.
pid = os.getpid()
Expand All @@ -46,3 +47,6 @@ def _run(self):
yield from tulip.sleep(1.0)
except KeyboardInterrupt:
pass

for server in servers:
server.close()
3 changes: 1 addition & 2 deletions tests/worker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def test_factory(self):

self.assertIsInstance(f, WSGIServerHttpProtocol)

@unittest.mock.patch('asynchttp.worker.tulip')
def test__run(self, m_tulip):
def test__run(self):
self.worker.ppid = 1
self.worker.alive = True
self.worker.sockets = [unittest.mock.Mock()]
Expand Down

0 comments on commit 8061d03

Please sign in to comment.