Browse Source
Merge pull request #63 from DistantJragon/ensure-conn-closed
Ensure connections are cleaned up
master
Gabriel Huber
2 days ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
10 additions and
6 deletions
-
a2s/a2s_async.py
-
a2s/a2s_sync.py
|
|
@ -19,9 +19,11 @@ logger = logging.getLogger("a2s") |
|
|
|
|
|
|
|
|
async def request_async(address, timeout, encoding, a2s_proto): |
|
|
async def request_async(address, timeout, encoding, a2s_proto): |
|
|
conn = await A2SStreamAsync.create(address, timeout) |
|
|
conn = await A2SStreamAsync.create(address, timeout) |
|
|
response = await request_async_impl(conn, encoding, a2s_proto) |
|
|
try: |
|
|
conn.close() |
|
|
response = await request_async_impl(conn, encoding, a2s_proto) |
|
|
return response |
|
|
return response |
|
|
|
|
|
finally: |
|
|
|
|
|
conn.close() |
|
|
|
|
|
|
|
|
async def request_async_impl(conn, encoding, a2s_proto, challenge=0, retries=0, ping=None): |
|
|
async def request_async_impl(conn, encoding, a2s_proto, challenge=0, retries=0, ping=None): |
|
|
send_time = time.monotonic() |
|
|
send_time = time.monotonic() |
|
|
|
|
|
@ -19,9 +19,11 @@ logger = logging.getLogger("a2s") |
|
|
|
|
|
|
|
|
def request_sync(address, timeout, encoding, a2s_proto): |
|
|
def request_sync(address, timeout, encoding, a2s_proto): |
|
|
conn = A2SStream(address, timeout) |
|
|
conn = A2SStream(address, timeout) |
|
|
response = request_sync_impl(conn, encoding, a2s_proto) |
|
|
try: |
|
|
conn.close() |
|
|
response = request_sync_impl(conn, encoding, a2s_proto) |
|
|
return response |
|
|
return response |
|
|
|
|
|
finally: |
|
|
|
|
|
conn.close() |
|
|
|
|
|
|
|
|
def request_sync_impl(conn, encoding, a2s_proto, challenge=0, retries=0, ping=None): |
|
|
def request_sync_impl(conn, encoding, a2s_proto, challenge=0, retries=0, ping=None): |
|
|
send_time = time.monotonic() |
|
|
send_time = time.monotonic() |
|
|
|