fix autopep8 format.
This commit is contained in:
parent
2d02ee85a8
commit
4efd476268
|
@ -1385,7 +1385,8 @@ class Task():
|
|||
try:
|
||||
self._executeInternal(te, wt) # TODO: no return value?
|
||||
except taos.error.ProgrammingError as err:
|
||||
errno2 = err.errno if (err.errno > 0) else 0x80000000 + err.errno # correct error scheme
|
||||
errno2 = err.errno if (
|
||||
err.errno > 0) else 0x80000000 + err.errno # correct error scheme
|
||||
if (errno2 in [
|
||||
0x05, # TSDB_CODE_RPC_NOT_READY
|
||||
0x200, 0x360, 0x362, 0x36A, 0x36B, 0x36D, 0x381, 0x380, 0x383, 0x503,
|
||||
|
@ -1393,7 +1394,9 @@ class Task():
|
|||
0x600,
|
||||
1000 # REST catch-all error
|
||||
]): # allowed errors
|
||||
self.logDebug("[=] Acceptable Taos library exception: errno=0x{:X}, msg: {}, SQL: {}".format(errno2, err, self._lastSql))
|
||||
self.logDebug(
|
||||
"[=] Acceptable Taos library exception: errno=0x{:X}, msg: {}, SQL: {}".format(
|
||||
errno2, err, self._lastSql))
|
||||
print("_", end="", flush=True)
|
||||
self._err = err
|
||||
else:
|
||||
|
@ -1862,6 +1865,7 @@ class MyLoggingAdapter(logging.LoggerAdapter):
|
|||
return "[{}]{}".format(threading.get_ident() % 10000, msg), kwargs
|
||||
# return '[%s] %s' % (self.extra['connid'], msg), kwargs
|
||||
|
||||
|
||||
class SvcManager:
|
||||
MAX_QUEUE_SIZE = 10000
|
||||
|
||||
|
@ -1873,17 +1877,20 @@ class SvcManager:
|
|||
self.ioThread = None
|
||||
self.subProcess = None
|
||||
self.shouldStop = False
|
||||
# self.status = MainExec.STATUS_RUNNING # set inside _startTaosService()
|
||||
# self.status = MainExec.STATUS_RUNNING # set inside
|
||||
# _startTaosService()
|
||||
|
||||
def svcOutputReader(self, out: IO, queue):
|
||||
# Important Reference: https://stackoverflow.com/questions/375427/non-blocking-read-on-a-subprocess-pipe-in-python
|
||||
# Important Reference:
|
||||
# https://stackoverflow.com/questions/375427/non-blocking-read-on-a-subprocess-pipe-in-python
|
||||
print("This is the svcOutput Reader...")
|
||||
# for line in out :
|
||||
for line in iter(out.readline, b''):
|
||||
# print("Finished reading a line: {}".format(line))
|
||||
# print("Adding item to queue...")
|
||||
line = line.decode("utf-8").rstrip()
|
||||
queue.put(line) # This might block, and then causing "out" buffer to block
|
||||
# This might block, and then causing "out" buffer to block
|
||||
queue.put(line)
|
||||
print("_i", end="", flush=True)
|
||||
|
||||
# Trim the queue if necessary
|
||||
|
@ -1901,7 +1908,8 @@ class SvcManager:
|
|||
break
|
||||
|
||||
# queue.put(line)
|
||||
print("\nNo more output (most likely) from IO thread managing TDengine service") # meaning sub process must have died
|
||||
# meaning sub process must have died
|
||||
print("\nNo more output (most likely) from IO thread managing TDengine service")
|
||||
out.close()
|
||||
|
||||
def _doMenu(self):
|
||||
|
@ -1932,7 +1940,9 @@ class SvcManager:
|
|||
|
||||
choice = self._doMenu()
|
||||
if choice == "1":
|
||||
self.sigHandlerResume() # TODO: can the sub-process be blocked due to us not reading from queue?
|
||||
# TODO: can the sub-process be blocked due to us not reading from
|
||||
# queue?
|
||||
self.sigHandlerResume()
|
||||
elif choice == "2":
|
||||
self.stopTaosService()
|
||||
elif choice == "3":
|
||||
|
@ -1963,8 +1973,10 @@ class SvcManager:
|
|||
print("Joining empty thread, doing nothing")
|
||||
|
||||
TD_READY_MSG = "TDengine is initialized successfully"
|
||||
|
||||
def _procIpcBatch(self):
|
||||
# Process all the output generated by the underlying sub process, managed by IO thread
|
||||
# Process all the output generated by the underlying sub process,
|
||||
# managed by IO thread
|
||||
while True:
|
||||
try:
|
||||
line = self.ipcQueue.get_nowait() # getting output at fast speed
|
||||
|
@ -1987,7 +1999,8 @@ class SvcManager:
|
|||
|
||||
# check if the ioThread is still running
|
||||
if (not self.ioThread) or (not self.ioThread.is_alive()):
|
||||
print("IO Thread (with subprocess) has ended, main thread now exiting...")
|
||||
print(
|
||||
"IO Thread (with subprocess) has ended, main thread now exiting...")
|
||||
self.stopTaosService()
|
||||
self._procIpcBatch() # one more batch
|
||||
return # TODO: maybe one last batch?
|
||||
|
@ -2036,7 +2049,9 @@ class SvcManager:
|
|||
|
||||
if self.ioThread:
|
||||
raise RuntimeError("Corrupt thread state")
|
||||
self.ioThread = threading.Thread(target=self.svcOutputReader, args=(self.subProcess.stdout, self.ipcQueue))
|
||||
self.ioThread = threading.Thread(
|
||||
target=self.svcOutputReader, args=(
|
||||
self.subProcess.stdout, self.ipcQueue))
|
||||
self.ioThread.daemon = True # thread dies with the program
|
||||
self.ioThread.start()
|
||||
|
||||
|
@ -2051,12 +2066,15 @@ class SvcManager:
|
|||
if self.status == MainExec.STATUS_RUNNING:
|
||||
print("TDengine service READY to process requests")
|
||||
return # now we've started
|
||||
raise RuntimeError("TDengine service did not start successfully") # TODO: handle this better?
|
||||
# TODO: handle this better?
|
||||
raise RuntimeError("TDengine service did not start successfully")
|
||||
|
||||
def stopTaosService(self):
|
||||
# can be called from both main thread or signal handler
|
||||
print("Terminating TDengine service running as the sub process...")
|
||||
# Linux will send Control-C generated SIGINT to the TDengine process already, ref: https://unix.stackexchange.com/questions/176235/fork-and-how-signals-are-delivered-to-processes
|
||||
# Linux will send Control-C generated SIGINT to the TDengine process
|
||||
# already, ref:
|
||||
# https://unix.stackexchange.com/questions/176235/fork-and-how-signals-are-delivered-to-processes
|
||||
if not self.subProcess:
|
||||
print("Process already stopped")
|
||||
return
|
||||
|
@ -2065,8 +2083,11 @@ class SvcManager:
|
|||
if retCode: # valid return code, process ended
|
||||
self.subProcess = None
|
||||
else: # process still alive, let's interrupt it
|
||||
print("Sub process still running, sending SIG_INT and waiting for it to stop...")
|
||||
self.subProcess.send_signal(signal.SIGINT) # sub process should end, then IPC queue should end, causing IO thread to end
|
||||
print(
|
||||
"Sub process still running, sending SIG_INT and waiting for it to stop...")
|
||||
# sub process should end, then IPC queue should end, causing IO
|
||||
# thread to end
|
||||
self.subProcess.send_signal(signal.SIGINT)
|
||||
try:
|
||||
self.subProcess.wait(10)
|
||||
except subprocess.TimeoutExpired as err:
|
||||
|
@ -2076,7 +2097,9 @@ class SvcManager:
|
|||
self.subProcess = None
|
||||
|
||||
if self.subProcess and (not self.subProcess.poll()):
|
||||
print("Sub process is still running... pid = {}".format(self.subProcess.pid))
|
||||
print(
|
||||
"Sub process is still running... pid = {}".format(
|
||||
self.subProcess.pid))
|
||||
|
||||
self.shouldStop = True
|
||||
self.joinIoThread()
|
||||
|
@ -2248,23 +2271,56 @@ def main():
|
|||
|
||||
'''))
|
||||
|
||||
parser.add_argument('-a', '--auto-start-service', action='store_true',
|
||||
parser.add_argument(
|
||||
'-a',
|
||||
'--auto-start-service',
|
||||
action='store_true',
|
||||
help='Automatically start/stop the TDengine service (default: false)')
|
||||
parser.add_argument('-c', '--connector-type', action='store', default='native', type=str,
|
||||
parser.add_argument(
|
||||
'-c',
|
||||
'--connector-type',
|
||||
action='store',
|
||||
default='native',
|
||||
type=str,
|
||||
help='Connector type to use: native, rest, or mixed (default: 10)')
|
||||
parser.add_argument('-d', '--debug', action='store_true',
|
||||
parser.add_argument(
|
||||
'-d',
|
||||
'--debug',
|
||||
action='store_true',
|
||||
help='Turn on DEBUG mode for more logging (default: false)')
|
||||
parser.add_argument('-e', '--run-tdengine', action='store_true',
|
||||
parser.add_argument(
|
||||
'-e',
|
||||
'--run-tdengine',
|
||||
action='store_true',
|
||||
help='Run TDengine service in foreground (default: false)')
|
||||
parser.add_argument('-l', '--larger-data', action='store_true',
|
||||
parser.add_argument(
|
||||
'-l',
|
||||
'--larger-data',
|
||||
action='store_true',
|
||||
help='Write larger amount of data during write operations (default: false)')
|
||||
parser.add_argument('-p', '--per-thread-db-connection', action='store_true',
|
||||
parser.add_argument(
|
||||
'-p',
|
||||
'--per-thread-db-connection',
|
||||
action='store_true',
|
||||
help='Use a single shared db connection (default: false)')
|
||||
parser.add_argument('-r', '--record-ops', action='store_true',
|
||||
parser.add_argument(
|
||||
'-r',
|
||||
'--record-ops',
|
||||
action='store_true',
|
||||
help='Use a pair of always-fsynced fils to record operations performing + performed, for power-off tests (default: false)')
|
||||
parser.add_argument('-s', '--max-steps', action='store', default=1000, type=int,
|
||||
parser.add_argument(
|
||||
'-s',
|
||||
'--max-steps',
|
||||
action='store',
|
||||
default=1000,
|
||||
type=int,
|
||||
help='Maximum number of steps to run (default: 100)')
|
||||
parser.add_argument('-t', '--num-threads', action='store', default=5, type=int,
|
||||
parser.add_argument(
|
||||
'-t',
|
||||
'--num-threads',
|
||||
action='store',
|
||||
default=5,
|
||||
type=int,
|
||||
help='Number of threads to run (default: 10)')
|
||||
|
||||
global gConfig
|
||||
|
|
Loading…
Reference in New Issue