Skip to content

Commit

Permalink
fixed typing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
visualDust committed Nov 23, 2023
1 parent e2b000a commit 3c09c16
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions neetbox.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "neetbox"

[logging]
level = "DEBUG"

[pipeline]
updateInterval = 10
Expand Down
8 changes: 2 additions & 6 deletions neetbox/daemon/client/_action_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_action_dict():
action_dict[name] = action.argspec.args
return action_dict

def eval_call(self, name: str, params: dict, callback: None):
def eval_call(name: str, params: dict, callback: None):
if name not in _NeetActionManager.__ACTION_POOL:
logger.err(f"Could not find action with name {name}, action stopped.")
return False
Expand Down Expand Up @@ -82,10 +82,6 @@ def _register(function: Callable, name: str = None, blocking: bool = False):
return function


# singleton
neet_action = _NeetActionManager()


# example
if __name__ == "__main__":
import time
Expand All @@ -102,6 +98,6 @@ def some(a, b):
def callback_fun(text):
print(f"callback_fun print: {text}")

neet_action.eval_call("some", {"a": "3", "b": "4"}, callback=callback_fun)
_NeetActionManager.eval_call(name="some", params={"a": "3", "b": "4"}, callback=callback_fun)
print("you should see this line first before callback_fun print")
time.sleep(4)
13 changes: 6 additions & 7 deletions neetbox/daemon/client/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Callable, Optional

import httpx
import websocket

from neetbox.config import get_module_level_config
from neetbox.core import Registry
Expand All @@ -14,11 +13,6 @@
httpx_logger = logging.getLogger("httpx")
httpx_logger.setLevel(logging.ERROR)

__no_proxy = {
"http://": None,
"https://": None,
}

EVENT_TYPE_NAME_KEY = "event-type"
EVENT_PAYLOAD_NAME_KEY = "payload"

Expand All @@ -34,7 +28,12 @@ def __init__(self) -> None:
cfg = get_module_level_config()

def __load_http_client():
__local_http_client = httpx.Client(proxies=__no_proxy) # type: ignore
__local_http_client = httpx.Client(
proxies={
"http://": None,
"https://": None,
}
) # type: ignore
return __local_http_client

# create htrtp client
Expand Down
2 changes: 1 addition & 1 deletion neetbox/daemon/server/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def ws_send(self):
- remove from connected_clients dict
on server receive json
- sent by client with name
- sent by client with name
- name exist: (name must exist)
- for websocket of frontend within name:
- forward message
Expand Down
6 changes: 4 additions & 2 deletions neetbox/pipeline/_signal_and_slot.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ def _watch(func: Callable, name: str, freq: float, initiative=False, force=False
force=force,
)
if initiative: # initiatively update the value dict when the function was called manually
logger.log(f"added {name} to daemon monitor. It will update on each call of the function.")
logger.debug(
f"added {name} to daemon monitor. It will update on each call of the function."
)
return partial(__update_and_get, name)
else:
logger.log(
logger.debug(
f"added {name} to daemon monitor. It will update every {freq*__TIME_UNIT_SEC} second(s)."
)
return partial(__get, name)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pyfiglet = "^1.0.2"
httpx = "^0.24.0"
flask = "^2.2.3"
flask-socketio = "^5.3.6"
websockets = "^12.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.0.0"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def test_neet_action():

@action(name="some_func")
def some(a, b):
time.sleep(1)
time.sleep(0.1)
return f"a = {a}, b = {b}"

print("registered actions:")
Expand All @@ -15,6 +15,6 @@ def some(a, b):
def callback_fun(text):
print(f"callback_fun print: {text}")

NeetActionManager.eval_call("some", {"a": "3", "b": "4"}, callback=callback_fun)
NeetActionManager.eval_call("some_func", params={"a": "3", "b": "4"}, callback=callback_fun)
print("you should see this line first before callback_fun print")
time.sleep(4)
time.sleep(0.2)

0 comments on commit 3c09c16

Please sign in to comment.