yuuki/libs/thread_control.py

34 lines
972 B
Python
Raw Normal View History

2019-12-31 21:45:14 +08:00
# -*- coding: utf-8 -*-
"""
Yuuki_Libs
(c) 2020 Star Inc.
2019-12-31 21:45:14 +08:00
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
2019-12-25 21:35:43 +08:00
import multiprocessing
import threading
2019-08-23 18:12:41 +08:00
class Yuuki_Thread:
2019-08-22 18:33:10 +08:00
def __init__(self):
2019-08-31 12:36:18 +08:00
self.lock = threading.Lock()
@staticmethod
def add(Yuuki_Func, args=()):
2019-08-31 12:36:18 +08:00
added_thread = threading.Thread(name=Yuuki_Func.__name__, target=Yuuki_Func, args=args)
added_thread.start()
@staticmethod
def getThreadInfo():
2019-08-31 12:36:18 +08:00
print(threading.active_count())
print(threading.enumerate())
print("{} add Threading\n".format(threading.current_thread()))
2019-12-25 21:35:43 +08:00
2019-10-11 21:43:05 +08:00
class Yuuki_Multiprocess:
@staticmethod
def add(Yuuki_Func, args=()):
2019-08-31 12:36:18 +08:00
added_multiprocess = multiprocessing.Process(name=Yuuki_Func.__name__, target=Yuuki_Func, args=args)
added_multiprocess.start()