andreped commited on
Commit
e32d549
·
unverified ·
2 Parent(s): 6c48ad1 b4647d9

Merge pull request #10 from andreped:shared-memory

Browse files

Implement singleton for shared memory between sessions

Files changed (2) hide show
  1. app.py +3 -6
  2. postly/clients/singleton_client.py +11 -0
app.py CHANGED
@@ -1,12 +1,9 @@
1
  import streamlit as st
2
 
3
- from postly.clients.postly_client import PostlyClient
4
 
5
- # Initialize the PostlyClient in Streamlit's session state
6
- if "client" not in st.session_state:
7
- st.session_state.client = PostlyClient()
8
-
9
- client = st.session_state.client
10
 
11
  # Initialize user session state
12
  if "logged_in" not in st.session_state:
 
1
  import streamlit as st
2
 
3
+ from postly.clients.singleton_client import SingletonPostlyClient
4
 
5
+ # Initialize the PostlyClient singleton
6
+ client = SingletonPostlyClient.get_instance()
 
 
 
7
 
8
  # Initialize user session state
9
  if "logged_in" not in st.session_state:
postly/clients/singleton_client.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .postly_client import PostlyClient
2
+
3
+
4
+ class SingletonPostlyClient:
5
+ _instance = None
6
+
7
+ @staticmethod
8
+ def get_instance():
9
+ if SingletonPostlyClient._instance is None:
10
+ SingletonPostlyClient._instance = PostlyClient()
11
+ return SingletonPostlyClient._instance