mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-15 00:30:33 +03:00
added threaded request helper
This commit is contained in:
parent
665548fde3
commit
984d09947c
@ -76,8 +76,15 @@ Plugins may use the killswitch system simply by hosting their own version of the
|
|||||||
using `killswitch.get_kill_switches(target='https://example.com/myplugin_killswitches.json')`. The returned object can
|
using `killswitch.get_kill_switches(target='https://example.com/myplugin_killswitches.json')`. The returned object can
|
||||||
be used to query the kill switch set, see the docstrings for more information on specifying versions.
|
be used to query the kill switch set, see the docstrings for more information on specifying versions.
|
||||||
|
|
||||||
The version of the JSON file will be automatically upgraded if possible by the code KillSwitch code. No behaviour changes will occur--Any killswitches defined in older
|
A helper method `killswitch.get_kill_switch_thread` is provided to allow for simple nonblocking requests for
|
||||||
versions will simply become unconditional kills in the new version.
|
KillSwitches. It starts a new thread, performs the HTTP request, and sends the results to the given callback.
|
||||||
|
|
||||||
|
**Note that your callback is invoked off-thread. Take precaution for locking if required, and do _NOT_ use tkinter**
|
||||||
|
**methods**
|
||||||
|
|
||||||
|
The version of the JSON file will be automatically upgraded if possible by the code KillSwitch code.
|
||||||
|
No behaviour changes will occur--Any killswitches defined in older versions will simply become unconditional kills in
|
||||||
|
the new version.
|
||||||
|
|
||||||
## Currently supported killswitch strings
|
## Currently supported killswitch strings
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
"""Fetch kill switches from EDMC Repo."""
|
"""Fetch kill switches from EDMC Repo."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import threading
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING, Any, Dict, List, Mapping, MutableMapping, MutableSequence, NamedTuple, Optional, Sequence, Tuple,
|
TYPE_CHECKING, Any, Callable, Dict, List, Mapping, MutableMapping, MutableSequence, NamedTuple, Optional, Sequence,
|
||||||
TypedDict, Union, cast
|
Tuple, TypedDict, Union, cast
|
||||||
)
|
)
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@ -414,6 +415,22 @@ def get_kill_switches(target=DEFAULT_KILLSWITCH_URL, fallback: Optional[str] = N
|
|||||||
return KillSwitchSet(parse_kill_switches(data))
|
return KillSwitchSet(parse_kill_switches(data))
|
||||||
|
|
||||||
|
|
||||||
|
def get_kill_switches_thread(
|
||||||
|
target, callback: Callable[[Optional[KillSwitchSet]], None], fallback: Optional[str] = None,
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Threaded version of get_kill_switches. Request is performed off thread, and callback is called when it is available.
|
||||||
|
|
||||||
|
:param target: Target killswitch file
|
||||||
|
:param callback: The callback to pass the newly created KillSwitchSet
|
||||||
|
:param fallback: Fallback killswitch file, if any, defaults to None
|
||||||
|
"""
|
||||||
|
def make_request():
|
||||||
|
callback(get_kill_switches(target, fallback=fallback))
|
||||||
|
|
||||||
|
threading.Thread(target=make_request, daemon=True).start()
|
||||||
|
|
||||||
|
|
||||||
active: KillSwitchSet = KillSwitchSet([])
|
active: KillSwitchSet = KillSwitchSet([])
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user