1- import sys
21import os
32import asyncio
43import subprocess
54import platform
65import configparser
76import psutil
87import logging
9- import io
108import re
119import threading
1210from .vars import THINGSDB_BIN
@@ -165,11 +163,21 @@ def write_config(self):
165163 config = configparser .RawConfigParser ()
166164 config .add_section ('thingsdb' )
167165
168- config .set ('thingsdb' , 'listen_client_port' , self .listen_client_port )
169- config .set ('thingsdb' , 'listen_node_port' , self .listen_node_port )
170- config .set ('thingsdb' , 'http_api_port' , self .http_api_port )
171- config .set ('thingsdb' , 'http_status_port' , self .http_status_port )
172- config .set ('thingsdb' , 'ws_port' , self .ws_port )
166+ config .set ('thingsdb' ,
167+ 'listen_client_port' ,
168+ str (self .listen_client_port ))
169+ config .set ('thingsdb' ,
170+ 'listen_node_port' ,
171+ str (self .listen_node_port ))
172+ config .set ('thingsdb' ,
173+ 'http_api_port' ,
174+ str (self .http_api_port ))
175+ config .set ('thingsdb' ,
176+ 'http_status_port' ,
177+ str (self .http_status_port ))
178+ config .set ('thingsdb' ,
179+ 'ws_port' ,
180+ str (self .ws_port ))
173181
174182 config .set ('thingsdb' , 'bind_client_addr' , self .bind_client_addr )
175183 config .set ('thingsdb' , 'bind_node_addr' , self .bind_node_addr )
@@ -270,13 +278,14 @@ def is_active(self):
270278 return False if self .proc is None else psutil .pid_exists (self .proc .pid )
271279
272280 def kill (self ):
273- command = f'kill -9 { self .proc .pid } '
274- logging .info (f'execute: `{ command } ``' )
275- os .system (command )
281+ if self .proc :
282+ command = f'kill -9 { self .proc .pid } '
283+ logging .info (f'execute: `{ command } ``' )
284+ os .system (command )
276285 self .proc = None
277286
278287 async def stop (self ):
279- if self .is_active ():
288+ if self .is_active () and self . proc :
280289 os .system ('kill {}' .format (self .proc .pid ))
281290 await asyncio .sleep (0.2 )
282291
@@ -291,7 +300,7 @@ async def stop(self):
291300 return True
292301
293302 async def shutdown (self , timeout = 20 ):
294- if self .is_active ():
303+ if self .is_active () and self . proc :
295304 os .system ('kill {}' .format (self .proc .pid ))
296305
297306 while timeout :
@@ -304,6 +313,6 @@ async def shutdown(self, timeout=20):
304313 assert (self .proc .returncode == 0 )
305314
306315 def soft_kill (self ):
307- if self .is_active ():
316+ if self .is_active () and self . proc :
308317 os .system ('kill {}' .format (self .proc .pid ))
309318 self .proc = None
0 commit comments