forked from oracle/python-cx_Oracle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect_pool2.py
More file actions
38 lines (30 loc) · 1.27 KB
/
connect_pool2.py
File metadata and controls
38 lines (30 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#------------------------------------------------------------------------------
# connect_pool2.py (Section 2.5)
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Copyright 2017, Oracle and/or its affiliates. All rights reserved.
#------------------------------------------------------------------------------
import cx_Oracle
import threading
import time
pool = cx_Oracle.SessionPool("pythonhol", "welcome", "localhost/orclpdb:pooled",
min = 2, max = 5, increment = 1, threaded = True)
def Query():
con = pool.acquire(cclass="PYTHONHOL", purity=cx_Oracle.ATTR_PURITY_SELF)
#con = pool.acquire(cclass="PYTHONHOL", purity=cx_Oracle.ATTR_PURITY_NEW)
cur = con.cursor()
for i in range(4):
cur.execute("select myseq.nextval from dual")
seqval, = cur.fetchone()
print("Thread", threading.current_thread().name, "fetched sequence =", seqval)
#time.sleep(1)
numberOfThreads = 5
threadArray = []
for i in range(numberOfThreads):
thread = threading.Thread(name='#'+str(i), target=Query)
threadArray.append(thread)
#time.sleep(4)
thread.start()
for t in threadArray:
t.join()
print("All done!")