Skip to content

Commit

Permalink
Compat with 3.12, drop 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
almarklein committed Apr 18, 2024
1 parent 4b4a5ce commit b923581
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ jobs:
- name: Linux py311
os: ubuntu-latest
pyversion: '3.11'
- name: Linux py312
os: ubuntu-latest
pyversion: '3.12'
- name: Windows py311
os: windows-latest
pyversion: '3.11'
Expand Down
15 changes: 7 additions & 8 deletions itemdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
json_encode = json.JSONEncoder(ensure_ascii=True).encode
json_decode = json.JSONDecoder().decode

is_py36 = sys.version_info < (3, 7)


# Notes:
#
Expand Down Expand Up @@ -64,7 +62,7 @@ def threaded_func(loop, future, args, kwargs):
loop.call_soon_threadsafe(future.set_result, result)

async def asyncified_func(*args, **kwargs):
loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()
future = loop.create_future()
threading.Thread(
name="asyncify " + func.__name__,
Expand Down Expand Up @@ -605,6 +603,7 @@ class AsyncItemDB:

async def __new__(cls, filename):
self = super().__new__(cls)
self._loop = asyncio.get_running_loop()
self._queue = queue.Queue()
self._thread = Thread4AsyncItemDB(self._queue)
self._thread.start()
Expand All @@ -616,7 +615,7 @@ def mtime(self):
return self.db.mtime

async def _handle(self, function, *args, **kwargs):
future = asyncio.get_event_loop().create_future()
future = self._loop.create_future()
self._queue.put_nowait((future, function, args, kwargs))
return await future

Expand All @@ -627,12 +626,12 @@ async def __aexit__(self, type, value, traceback):
return await self._handle(self.db.__exit__, type, value, traceback)

def __del__(self):
future = asyncio.get_event_loop().create_future()
future = self._loop.create_future()
self._queue.put_nowait((future, self.db.close, (), {}))
self._queue.put_nowait((None, None, None, None))

async def close(self):
future = asyncio.get_event_loop().create_future()
future = self._loop.create_future()
self._queue.put_nowait((future, self.db.close, (), {}))
self._queue.put_nowait((None, None, None, None))
return await future
Expand Down Expand Up @@ -704,7 +703,7 @@ def set_result(fut, result):
if not fut.done():
fut.set_result(result)

loop = future._loop if is_py36 else future.get_loop()
loop = future.get_loop()
loop.call_soon_threadsafe(set_result, future, result)

except BaseException as e:
Expand All @@ -713,5 +712,5 @@ def set_exception(fut, e):
if not fut.done():
fut.set_exception(e)

loop = future._loop if is_py36 else future.get_loop()
loop = future.get_loop()
loop.call_soon_threadsafe(set_exception, future, e)
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_version_and_doc(filename):
description="Easy transactional database for Python dicts, backed by SQLite",
long_description=doc,
platforms="any",
python_requires=">=3.6",
python_requires=">=3.7",
install_requires=[],
py_modules=["itemdb"],
zip_safe=True,
Expand All @@ -60,9 +60,10 @@ def get_version_and_doc(filename):
"Operating System :: POSIX",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
)

0 comments on commit b923581

Please sign in to comment.