Skip to content

Commit ea5bbb2

Browse files
author
=
committed
Replaced more powerful thread pool executor
1 parent 4df7006 commit ea5bbb2

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A very simple asynchronous wrapper that makes you can access to Oracle in asynci
1010
Easy to use , buy may not the best practice for efficiency concern.
1111

1212
## Requirements
13-
- [cx_Oracle >= 8.1.0](https://github.com/aio-libs/aiohttp) (Take into consideration that author of cx_Oracle said he's trying to implement asyncio support , APIs maybe change in future version. Switch to 8.1.0 if there's something wrong makes it not gonna work.)
13+
- [cx_Oracle >= 8.1.0](https://github.com/oracle/python-cx_Oracle) (Take into consideration that author of cx_Oracle said he's trying to implement asyncio support , APIs maybe change in future version. Switch to 8.1.0 if there's something wrong makes it not gonna work.)
1414

1515
## Install
1616

cx_Oracle_async/utils.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import asyncio
22
import cx_Oracle as csor
3-
import platform
4-
from concurrent.futures import ThreadPoolExecutor
3+
from ThreadPoolExecutorPlus import ThreadPoolExecutor
54

6-
class AsyncCursorWarper:
5+
class AsyncCursorWarpper:
76

87
def __init__(self , loop , thread_pool , cursor):
98
self._loop = loop
@@ -29,8 +28,11 @@ async def fetchall(self):
2928
async def fetchone(self):
3029
return await self._loop.run_in_executor(self._thread_pool , self._cursor.fetchone)
3130

31+
async def var(self, args):
32+
return await self._loop.run_in_executor(self._thread_pool , self._cursor.var, args)
3233

33-
class AsyncCursorWarper_context:
34+
35+
class AsyncCursorWarpper_context:
3436

3537
def __init__(self , loop , thread_pool , conn):
3638
self._loop = loop
@@ -39,25 +41,25 @@ def __init__(self , loop , thread_pool , conn):
3941

4042
async def __aenter__(self):
4143
cursor = await self._loop.run_in_executor(self._thread_pool , self._conn.cursor)
42-
return AsyncCursorWarper(self._loop , self._thread_pool , cursor)
44+
return AsyncCursorWarpper(self._loop , self._thread_pool , cursor)
4345

4446
async def __aexit__(self, exc_type, exc, tb):
4547
return
4648

47-
class AsyncConnectionWarper:
49+
class AsyncConnectionWarpper:
4850

4951
def __init__(self , loop , thread_pool , conn):
5052
self._loop = loop
5153
self._thread_pool = thread_pool
5254
self._conn = conn
5355

5456
def cursor(self):
55-
return AsyncCursorWarper_context(self._loop , self._thread_pool , self._conn)
57+
return AsyncCursorWarpper_context(self._loop , self._thread_pool , self._conn)
5658

5759
async def commit(self):
5860
await self._loop.run_in_executor(self._thread_pool , self._conn.commit)
5961

60-
class AsyncConnectionWarper_context:
62+
class AsyncConnectionWarpper_context:
6163

6264
def __init__(self , loop , thread_pool , pool ):
6365
self._loop = loop
@@ -66,12 +68,12 @@ def __init__(self , loop , thread_pool , pool ):
6668

6769
async def __aenter__(self):
6870
self._conn = await self._loop.run_in_executor(self._thread_pool , self._pool.acquire)
69-
return AsyncConnectionWarper(self._loop , self._thread_pool , self._conn)
71+
return AsyncConnectionWarpper(self._loop , self._thread_pool , self._conn)
7072

7173
async def __aexit__(self, exc_type, exc, tb):
7274
await self._loop.run_in_executor(self._thread_pool , self._pool.release , self._conn)
7375

74-
class AsyncPoolWarper:
76+
class AsyncPoolWarpper:
7577

7678
def __init__(self , pool , loop = None):
7779

@@ -88,19 +90,12 @@ def _test():
8890
8991
Issue if you have better implementation.
9092
'''
91-
pltfm = platform.system()
92-
if pltfm == 'Windows':
93-
_t_num = 512
94-
elif pltfm == 'Linux':
95-
_t_num = 1024
96-
else:
97-
raise RuntimeError("We havent decided how many threads should acquire on your platform. Maybe you have to modify source code your self.")
98-
self._thread_pool = ThreadPoolExecutor(max_workers = _t_num)
93+
self._thread_pool = ThreadPoolExecutor()
9994
self._loop = loop
10095
self._pool = pool
10196

10297
def acquire(self):
103-
return AsyncConnectionWarper_context(self._loop , self._thread_pool , self._pool)
98+
return AsyncConnectionWarpper_context(self._loop , self._thread_pool , self._pool)
10499

105100
async def preexciting(self):
106101

@@ -114,7 +109,7 @@ async def create_pool(host = 'localhost', port = '1521' , user = 'sys', password
114109
if loop == None:
115110
loop = asyncio.get_running_loop()
116111
pool = csor.SessionPool(user , password , f"{host}:{port}/{db}", min = minsize , max = maxsize , increment = 1 , threaded = True , encoding = encoding)
117-
pool = AsyncPoolWarper(pool)
112+
pool = AsyncPoolWarpper(pool)
118113
await pool.preexciting()
119114
return pool
120115

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
cx-Oracle>=8.1.0
1+
cx-Oracle>=8.1.0
2+
ThreadPoolExecutorPlus>=0.1.1

0 commit comments

Comments
 (0)