Skip to content

Commit

Permalink
switching Session is easier
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Jun 2, 2024
1 parent 548632b commit 719dabf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions htagweb/hrprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from htag.render import HRenderer
import aiofiles

from . import session
from .session import Session
from .fifo import Fifo

import logging
Expand All @@ -31,7 +31,7 @@ async def main(f:Fifo,moduleapp:str,timeout_interaction,timeout_inactivity):
with open(f.PID_FILE,"w+") as fid:
fid.write(str(os.getpid()))

ses=session.FileDict(f.uid)
ses=Session(f.uid)

sys.hr=None # save as global, in sys module (bad practice !!! but got sense)
sys.running=True
Expand Down
4 changes: 2 additions & 2 deletions htagweb/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
from . import crypto
from . import session
from .session import Session
from .fqn import findfqn
from .hrclient import HrClient
#/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Expand Down Expand Up @@ -72,7 +72,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:

#!!!!!!!!!!!!!!!!!!!!!!!!!!!
scope["uid"] = uid
scope["session"] = session.FileDict(uid) # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
scope["session"] = Session(uid) # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#!!!!!!!!!!!!!!!!!!!!!!!!!!!

logger.debug("request for %s, scope=%s",uid,scope)
Expand Down
23 changes: 12 additions & 11 deletions htagweb/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ def __init__(self,uid):
FileDict.__init__(self,uid,persistent=True)


# from shared_memory_dict import SharedMemoryDict
# class ShmDict(SharedMemoryDict):
# def __init__(self,uid):
# self._uid=uid
# SharedMemoryDict.__init__(self,name=uid, size=10240)
try:
from shared_memory_dict import SharedMemoryDict
class ShmDict(SharedMemoryDict):
def __init__(self,uid):
self._uid=uid
SharedMemoryDict.__init__(self,name=uid, size=10240)

# def _save(self):
# print(":::::::::::::::::::::::::::::::::::::::::::::::",flush=True)
# print(dict(self),flush=True)
# print(":::::::::::::::::::::::::::::::::::::::::::::::",flush=True)
def _save(self):
pass
except ImportError:
pass

Session = FileDict
5 changes: 4 additions & 1 deletion test_sessions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest,asyncio,sys
from htagweb.session import FileDict,FilePersistentDict #,ShmDict
from htagweb.session import Session,FileDict,FilePersistentDict #,ShmDict


def session_test(factory):
Expand Down Expand Up @@ -40,6 +40,9 @@ def session_test(factory):
finally:
session.clear()

def test_sessions_file():
session_test( Session )

def test_sessions_file():
session_test( FileDict )

Expand Down

0 comments on commit 719dabf

Please sign in to comment.