forked from exasol/pyexasol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
28_thread_safety.py
44 lines (33 loc) · 1.01 KB
/
28_thread_safety.py
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
39
40
41
42
43
44
"""
Example 28
Attempt to access connection object from multiple threads simultaneously
"""
import pyexasol
import time
import threading
import _config as config
import pprint
printer = pprint.PrettyPrinter(indent=4, width=140)
class QueryThread(threading.Thread):
def __init__(self, connection):
self.connection = connection
super().__init__()
def run(self):
# Run heavy query
try:
self.connection.execute("SELECT * FROM users a, users b, users c, payments d")
except pyexasol.ExaQueryAbortError as e:
print(e.message)
except pyexasol.ExaConcurrencyError as e:
print(e.message)
# Basic connect
C = pyexasol.connect(dsn=config.dsn, user=config.user, password=config.password, schema=config.schema)
# Try to run multiple query threads in parallel
query_thread_1 = QueryThread(C)
query_thread_2 = QueryThread(C)
query_thread_1.start()
query_thread_2.start()
time.sleep(1)
C.abort_query()
query_thread_1.join()
query_thread_2.join()