Skip to content

Commit b4a4c5d

Browse files
cmickeybprakashngit
authored andcommitted
use atexit to make shutdown of replication workers automatic
Signed-off-by: Mic Bowman <[email protected]>
1 parent 73f09ba commit b4a4c5d

File tree

4 files changed

+6
-15
lines changed

4 files changed

+6
-15
lines changed

client/pdo/client/scripts/ShellCLI.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ def LocalMain(config) :
3737

3838
logger.info("Processing script file %s", str(script_file))
3939
exit_code = ContractController.ProcessScript(shell, script_file)
40-
ContractResponse.exit_commit_workers()
4140
sys.exit(exit_code)
4241

4342
shell = ContractController.CreateController(config, echo=True, interactive=True)
4443
shell.cmdloop()
4544
print("")
4645

47-
ContractResponse.exit_commit_workers()
4846
sys.exit(shell.exit_code)
4947

5048
## XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

python/pdo/contract/response.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import atexit
16+
1517
from pdo.contract.invocation import invocation_response
1618
import pdo.common.crypto as crypto
1719
from pdo.common.utility import deprecated
@@ -42,12 +44,13 @@ class ContractResponse(object) :
4244

4345
# -------------------------------------------------------
4446
@staticmethod
45-
def exit_commit_workers():
47+
def __exit_commit_workers__():
4648
"""Set the global variable stop_commit_service to True. This will be picked by the workers"""
4749

4850
if ContractResponse.__start_commit_service__ is False: #if True no service has yet been started
4951
stop_replication_service()
5052
stop_transacion_processing_service()
53+
ContractResponse.__start_commit_service__ = True
5154

5255
# -------------------------------------------------------
5356
def __init__(self, request, response) :
@@ -101,6 +104,8 @@ def commit_asynchronously(self, ledger_config=None, wait_parameter_for_ledger=30
101104

102105
#start threads for commiting response if not done before
103106
if ContractResponse.__start_commit_service__:
107+
atexit.register(ContractResponse.__exit_commit_workers__)
108+
104109
# start replication service
105110
start_replication_service()
106111
start_transaction_processing_service()

python/pdo/test/contract.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ def ErrorShutdown() :
7070
except Exception as e :
7171
logger.exception('shutdown failed')
7272

73-
# Send termination signal to commit tasks
74-
ContractResponse.exit_commit_workers()
75-
7673
sys.exit(-1)
7774

7875
# -----------------------------------------------------------------
@@ -464,9 +461,6 @@ def UpdateTheContract(config, enclaves, contract, contract_invoker_keys) :
464461
logger.info('completed in %s', time.time() - start_time)
465462
logger.info('passed %d of %d tests', total_tests - total_failed, total_tests)
466463

467-
#shutdown commit workers
468-
ContractResponse.exit_commit_workers()
469-
470464
# -----------------------------------------------------------------
471465
# -----------------------------------------------------------------
472466
def LocalMain(config) :

python/pdo/test/request.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ def ErrorShutdown() :
6969
except Exception as e :
7070
logger.exception('shutdown failed')
7171

72-
# Send termination signal to commit tasks
73-
ContractResponse.exit_commit_workers()
74-
7572
sys.exit(-1)
7673

7774
# -----------------------------------------------------------------
@@ -384,9 +381,6 @@ def UpdateTheContract(config, contract, enclaves, contract_invoker_keys) :
384381
logger.info("All commits completed")
385382
logger.info('completed in %s', time.time() - start_time)
386383

387-
# shutdown commit workers
388-
ContractResponse.exit_commit_workers()
389-
390384
# -----------------------------------------------------------------
391385
# -----------------------------------------------------------------
392386
def LocalMain(config) :

0 commit comments

Comments
 (0)