V 0.4.5 commit
update(not done)
This commit is contained in:
parent
22f448ec28
commit
0b4a4b6145
40
bin/new_thread.py
Normal file
40
bin/new_thread.py
Normal file
@ -0,0 +1,40 @@
|
||||
import functools
|
||||
import inspect
|
||||
import threading
|
||||
from typing import Optional, Callable
|
||||
|
||||
"""
|
||||
This part of code come from MCDReforged(https://github.com/Fallen_Breath/MCDReforged)
|
||||
Very thanks to Fallen_Breath and other coder who helped MCDR worked better
|
||||
https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
"""
|
||||
|
||||
|
||||
def new_thread(thread_name: Optional[str or Callable] = None):
|
||||
"""
|
||||
Use a new thread to execute the decorated function
|
||||
The function return value will be set to the thread instance that executes this function
|
||||
The name of the thread can be specified in parameter
|
||||
"""
|
||||
|
||||
def wrapper(func):
|
||||
@functools.wraps(func) # to preserve the origin function information
|
||||
def wrap(*args, **kwargs):
|
||||
thread = threading.Thread(target=func, args=args, kwargs=kwargs, name=thread_name)
|
||||
thread.setDaemon(True)
|
||||
thread.start()
|
||||
return thread
|
||||
|
||||
# bring the signature of the func to the wrap function
|
||||
# so inspect.getfullargspec(func) works correctly
|
||||
# https://stackoverflow.com/questions/39926567find/python-create-decorator-preserving-function-arguments
|
||||
wrap.__signature__ = inspect.signature(func)
|
||||
return wrap
|
||||
|
||||
# Directly use @on_new_thread without ending brackets case
|
||||
if isinstance(thread_name, Callable):
|
||||
this_is_a_function = thread_name
|
||||
thread_name = None
|
||||
return wrapper(this_is_a_function)
|
||||
# Use @on_new_thread with ending brackets case
|
||||
return wrapper
|
@ -16,17 +16,17 @@
|
||||
|
||||
### Change
|
||||
|
||||
- function tools.config()'s way of raise error change tools.report_file_error()
|
||||
- function tools.cb() change name to tools.format_bool()
|
||||
- function `tools.config()` way of raise error change `tools.report_file_error()`
|
||||
- function `tools.cb()` change name to `tools.format_bool()`
|
||||
- config.py clear some useless import class
|
||||
- changing configfile to main.config *doing
|
||||
|
||||
### Test change
|
||||
|
||||
- test_config_file.py
|
||||
- test_for_speed.py
|
||||
- test_logging_conf.py
|
||||
- test_speed_of_sprite.py
|
||||
- `test_config_file.py`
|
||||
- `test_for_speed.py`
|
||||
- `test_logging_conf.py`
|
||||
- `test_speed_of_sprite.py`
|
||||
|
||||
## 2021/06/26 V 0.4.3
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user