Skip to content

Commit

Permalink
V 0.4.5 commit
Browse files Browse the repository at this point in the history
update(not done)
  • Loading branch information
shenjackyuanjie committed Jul 14, 2021
1 parent 22f448e commit 0b4a4b6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
40 changes: 40 additions & 0 deletions bin/new_thread.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions docs/update_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0b4a4b6

Please sign in to comment.