Skip to content

Commit

Permalink
Resolved master and outstation not shutdown gracefully issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
kefeimo committed Oct 30, 2022
1 parent 49ebb36 commit 412c17b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
26 changes: 21 additions & 5 deletions src/dnp3_python/dnp3station/master_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,12 +582,28 @@ def start(self):
self.master.Enable()

def shutdown(self):
# print("=======before master del self.__dict", self.__dict__)
"""
Execute an orderly shutdown of the Master.
The debug messages may be helpful if errors occur during shutdown.
Expected:
channel state change: SHUTDOWN
ms(1667103120775) INFO manager - Exiting thread (0)
Note:
Note: Don't use `self.manager.Shutdown()`, otherwise
"Process finished with exit code 134 (interrupted by signal 6: SIGABRT)"
Use `del self.master` instead of `self.master.Shutdown()`, otherwise
Process hanging
"""

sleep_before_master_shutdown = 2
_log.info(f"Master station shutting down in {sleep_before_master_shutdown} seconds...")
time.sleep(sleep_before_master_shutdown) # Note: hard-coded sleep to avoid hanging process
del self.slow_scan
del self.fast_scan
# del self.master
del self.master
del self.channel
del self.manager
# self.master.Shutdown()
self.channel.Shutdown()

# self.manager.Shutdown()
29 changes: 13 additions & 16 deletions src/dnp3_python/dnp3station/outstation_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,26 +225,23 @@ def start(self):

def shutdown(self):
"""
Execute an orderly shutdown of the Outstation.
Execute an orderly shutdown of the Outstation.
The debug messages may be helpful if errors occur during shutdown.
The debug messages may be helpful if errors occur during shutdown.
Expected:
ms(1667102887814) INFO server - Operation aborted.
ms(1667102887821) INFO manager - Exiting thread (0)
Note:
Note: Don't use `self.manager.Shutdown()`, otherwise
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
"""
# TODO: cannot shut down: see Outstation and master hang on shutdown #1 at
# https: // github.com / ChargePoint / pydnp3 / issues / 1
time.sleep(2) # Note: hard-coded sleep to avoid hanging process
_outstation = self.get_outstation()
del _outstation
del self.channel
del self.log_handler
del self.outstation_application
del self.stack_config
del self.command_handler
del self.listener
del self.retry_parameters
# del self.manager

self.manager.Shutdown() # Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
# self.manager.__del__() # Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
_outstation.Shutdown()
self.channel.Shutdown()

# self.manager.Shutdown()

@classmethod # TODO: Justify the necessity to use class method
def get_outstation(cls):
Expand Down

0 comments on commit 412c17b

Please sign in to comment.