Python3 Migrate

This commit is contained in:
MariuszC
2020-01-18 20:01:00 +01:00
parent ea05af2d15
commit 6cd7e0fe44
691 changed files with 201846 additions and 598 deletions

View File

@@ -0,0 +1,53 @@
import logging
import threading
import pykka
import _thread
logger = logging.getLogger(__name__)
def exit_process():
logger.debug("Interrupting main...")
_thread.interrupt_main()
logger.debug("Interrupted main")
def sigterm_handler(signum, frame):
"""A :mod:`signal` handler which will exit the program on signal.
This function is not called when the process' main thread is running a GLib
mainloop. In that case, the GLib mainloop must listen for SIGTERM signals
and quit itself.
For Mopidy subcommands that does not run the GLib mainloop, this handler
ensures a proper shutdown of the process on SIGTERM.
"""
logger.info("Got SIGTERM signal. Exiting...")
exit_process()
def stop_actors_by_class(klass):
actors = pykka.ActorRegistry.get_by_class(klass)
logger.debug("Stopping %d instance(s) of %s", len(actors), klass.__name__)
for actor in actors:
actor.stop()
def stop_remaining_actors():
num_actors = len(pykka.ActorRegistry.get_all())
while num_actors:
logger.error(
"There are actor threads still running, this is probably a bug"
)
logger.debug(
"Seeing %d actor and %d non-actor thread(s): %s",
num_actors,
threading.active_count() - num_actors,
", ".join([t.name for t in threading.enumerate()]),
)
logger.debug("Stopping %d actor(s)...", num_actors)
pykka.ActorRegistry.stop_all()
num_actors = len(pykka.ActorRegistry.get_all())
logger.debug("All actors stopped.")