fix more threading API related bugs
This commit is contained in:
parent
2d9a086410
commit
b03ca4bc68
|
@ -9,7 +9,7 @@ import time
|
|||
from pprint import pprint
|
||||
|
||||
try:
|
||||
from threading import Thread, currentThread
|
||||
from threading import Thread, current_thread
|
||||
have_threads = 1
|
||||
except ImportError:
|
||||
have_threads = 0
|
||||
|
|
|
@ -8,7 +8,7 @@ import time
|
|||
from pprint import pprint
|
||||
|
||||
try:
|
||||
from threading import Thread, currentThread
|
||||
from threading import Thread, current_thread
|
||||
have_threads = 1
|
||||
except ImportError:
|
||||
have_threads = 0
|
||||
|
|
|
@ -7,7 +7,7 @@ import tempfile
|
|||
import time
|
||||
|
||||
try:
|
||||
from threading import Thread, currentThread
|
||||
from threading import Thread, current_thread
|
||||
have_threads = 1
|
||||
except ImportError:
|
||||
have_threads = 0
|
||||
|
@ -117,7 +117,7 @@ class LockingTestCase(unittest.TestCase):
|
|||
deadlock_detection.end=False
|
||||
deadlock_detection.count=0
|
||||
t=Thread(target=deadlock_detection)
|
||||
t.setDaemon(True)
|
||||
t.set_daemon(True)
|
||||
t.start()
|
||||
self.env.set_timeout(100000, db.DB_SET_LOCK_TIMEOUT)
|
||||
anID = self.env.lock_id()
|
||||
|
@ -143,7 +143,7 @@ class LockingTestCase(unittest.TestCase):
|
|||
self.assertTrue(deadlock_detection.count>0)
|
||||
|
||||
def theThread(self, sleepTime, lockType):
|
||||
name = currentThread().getName()
|
||||
name = current_thread().get_name()
|
||||
if lockType == db.DB_LOCK_WRITE:
|
||||
lt = "write"
|
||||
else:
|
||||
|
|
|
@ -12,7 +12,7 @@ from random import random
|
|||
DASH = b'-'
|
||||
|
||||
try:
|
||||
from threading import Thread, currentThread
|
||||
from threading import Thread, current_thread
|
||||
have_threads = True
|
||||
except ImportError:
|
||||
have_threads = False
|
||||
|
@ -89,20 +89,20 @@ class BaseThreadedTestCase(unittest.TestCase):
|
|||
self._writerThread(*args, **kwargs)
|
||||
except db.DBLockDeadlockError:
|
||||
if verbose:
|
||||
print(currentThread().getName(), 'died from', e)
|
||||
print(current_thread().get_name(), 'died from', e)
|
||||
else:
|
||||
if verbose:
|
||||
print(currentThread().getName(), "finished.")
|
||||
print(current_thread().get_name(), "finished.")
|
||||
|
||||
def readerThread(self, *args, **kwargs):
|
||||
try:
|
||||
self._readerThread(*args, **kwargs)
|
||||
except db.DBLockDeadlockError as e:
|
||||
if verbose:
|
||||
print(currentThread().getName(), 'died from', e)
|
||||
print(current_thread().get_name(), 'died from', e)
|
||||
else:
|
||||
if verbose:
|
||||
print(currentThread().getName(), "finished.")
|
||||
print(current_thread().get_name(), "finished.")
|
||||
|
||||
|
||||
|
||||
|
@ -143,7 +143,7 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
|
|||
t.join()
|
||||
|
||||
def _writerThread(self, d, howMany):
|
||||
name = currentThread().getName()
|
||||
name = current_thread().get_name()
|
||||
start = 0
|
||||
stop = howMany
|
||||
if verbose:
|
||||
|
@ -172,7 +172,7 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
|
|||
|
||||
def _readerThread(self, d, readerNum):
|
||||
time.sleep(0.01 * readerNum)
|
||||
name = currentThread().getName()
|
||||
name = current_thread().get_name()
|
||||
|
||||
for loop in range(5):
|
||||
c = d.cursor()
|
||||
|
@ -240,7 +240,7 @@ class SimpleThreadedBase(BaseThreadedTestCase):
|
|||
t.join()
|
||||
|
||||
def _writerThread(self, d, howMany, writerNum):
|
||||
name = currentThread().getName()
|
||||
name = current_thread().get_name()
|
||||
start = howMany * writerNum
|
||||
stop = howMany * (writerNum + 1) - 1
|
||||
if verbose:
|
||||
|
@ -286,7 +286,7 @@ class SimpleThreadedBase(BaseThreadedTestCase):
|
|||
|
||||
def _readerThread(self, d, readerNum):
|
||||
time.sleep(0.01 * readerNum)
|
||||
name = currentThread().getName()
|
||||
name = current_thread().get_name()
|
||||
|
||||
for loop in range(5):
|
||||
c = d.cursor()
|
||||
|
@ -385,7 +385,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
|
|||
time.sleep(0.05)
|
||||
|
||||
def _writerThread(self, d, howMany, writerNum):
|
||||
name = currentThread().getName()
|
||||
name = current_thread().get_name()
|
||||
start = howMany * writerNum
|
||||
stop = howMany * (writerNum + 1) - 1
|
||||
if verbose:
|
||||
|
@ -427,7 +427,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
|
|||
|
||||
def _readerThread(self, d, readerNum):
|
||||
time.sleep(0.01 * readerNum + 0.05)
|
||||
name = currentThread().getName()
|
||||
name = current_thread().get_name()
|
||||
|
||||
for loop in range(5):
|
||||
finished = False
|
||||
|
|
|
@ -106,7 +106,7 @@ class RPCServer(socketserver.TCPServer):
|
|||
erf = sys.__stderr__
|
||||
print('\n' + '-'*40, file=erf)
|
||||
print('Unhandled server exception!', file=erf)
|
||||
print('Thread: %s' % threading.currentThread().getName(), file=erf)
|
||||
print('Thread: %s' % threading.current_thread().get_name(), file=erf)
|
||||
print('Client Address: ', client_address, file=erf)
|
||||
print('Request: ', repr(request), file=erf)
|
||||
traceback.print_exc(file=erf)
|
||||
|
@ -126,7 +126,7 @@ class SocketIO(object):
|
|||
nextseq = 0
|
||||
|
||||
def __init__(self, sock, objtable=None, debugging=None):
|
||||
self.sockthread = threading.currentThread()
|
||||
self.sockthread = threading.current_thread()
|
||||
if debugging is not None:
|
||||
self.debugging = debugging
|
||||
self.sock = sock
|
||||
|
@ -149,7 +149,7 @@ class SocketIO(object):
|
|||
def debug(self, *args):
|
||||
if not self.debugging:
|
||||
return
|
||||
s = self.location + " " + str(threading.currentThread().getName())
|
||||
s = self.location + " " + str(threading.current_thread().getName())
|
||||
for a in args:
|
||||
s = s + " " + str(a)
|
||||
print(s, file=sys.__stderr__)
|
||||
|
@ -218,7 +218,7 @@ class SocketIO(object):
|
|||
def asynccall(self, oid, methodname, args, kwargs):
|
||||
request = ("CALL", (oid, methodname, args, kwargs))
|
||||
seq = self.newseq()
|
||||
if threading.currentThread() != self.sockthread:
|
||||
if threading.current_thread() != self.sockthread:
|
||||
cvar = threading.Condition()
|
||||
self.cvars[seq] = cvar
|
||||
self.debug(("asynccall:%d:" % seq), oid, methodname, args, kwargs)
|
||||
|
@ -228,7 +228,7 @@ class SocketIO(object):
|
|||
def asyncqueue(self, oid, methodname, args, kwargs):
|
||||
request = ("QUEUE", (oid, methodname, args, kwargs))
|
||||
seq = self.newseq()
|
||||
if threading.currentThread() != self.sockthread:
|
||||
if threading.current_thread() != self.sockthread:
|
||||
cvar = threading.Condition()
|
||||
self.cvars[seq] = cvar
|
||||
self.debug(("asyncqueue:%d:" % seq), oid, methodname, args, kwargs)
|
||||
|
@ -294,7 +294,7 @@ class SocketIO(object):
|
|||
|
||||
def _getresponse(self, myseq, wait):
|
||||
self.debug("_getresponse:myseq:", myseq)
|
||||
if threading.currentThread() is self.sockthread:
|
||||
if threading.current_thread() is self.sockthread:
|
||||
# this thread does all reading of requests or responses
|
||||
while 1:
|
||||
response = self.pollresponse(myseq, wait)
|
||||
|
|
|
@ -73,7 +73,7 @@ def main(del_exitfunc=False):
|
|||
sockthread = threading.Thread(target=manage_socket,
|
||||
name='SockThread',
|
||||
args=((LOCALHOST, port),))
|
||||
sockthread.setDaemon(True)
|
||||
sockthread.set_daemon(True)
|
||||
sockthread.start()
|
||||
while 1:
|
||||
try:
|
||||
|
@ -227,7 +227,7 @@ class MyRPCServer(rpc.RPCServer):
|
|||
erf = sys.__stderr__
|
||||
print('\n' + '-'*40, file=erf)
|
||||
print('Unhandled server exception!', file=erf)
|
||||
print('Thread: %s' % threading.currentThread().getName(), file=erf)
|
||||
print('Thread: %s' % threading.current_thread().get_name(), file=erf)
|
||||
print('Client Address: ', client_address, file=erf)
|
||||
print('Request: ', repr(request), file=erf)
|
||||
traceback.print_exc(file=erf)
|
||||
|
|
|
@ -566,7 +566,7 @@ class ThreadingMixIn:
|
|||
t = threading.Thread(target = self.process_request_thread,
|
||||
args = (request, client_address))
|
||||
if self.daemon_threads:
|
||||
t.setDaemon (1)
|
||||
t.set_daemon(True)
|
||||
t.start()
|
||||
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ class ThreadedTempFileTest(unittest.TestCase):
|
|||
t.join()
|
||||
ok += t.ok_count
|
||||
if t.error_count:
|
||||
errors.append(str(t.getName()) + str(t.errors.getvalue()))
|
||||
errors.append(str(t.get_name()) + str(t.errors.getvalue()))
|
||||
|
||||
threading_cleanup(*thread_info)
|
||||
|
||||
|
|
|
@ -856,7 +856,7 @@ def _test():
|
|||
P = []
|
||||
for i in range(NP):
|
||||
t = ProducerThread(Q, NI)
|
||||
t.setName("Producer-%d" % (i+1))
|
||||
t.set_name("Producer-%d" % (i+1))
|
||||
P.append(t)
|
||||
C = ConsumerThread(Q, NI*NP)
|
||||
for t in P:
|
||||
|
|
Loading…
Reference in New Issue