Hi i’m trying to create charts from thread per user session. But for some reason the column doesn’t get update. where as if i add sleep in rect() function works. Any help on this would be appreciated. Thanks!
from itertools import groupby
import param
import panel as pn
import holoviews as hv
import traceback as tb
from typing import List
import time
import os
import asyncio
from signalrcore.hub_connection_builder import HubConnectionBuilder
from concurrent.futures import ThreadPoolExecutor
from configs.sample_configs import WafermapSetup
from app.mgi import MGIMap, Interaction, MGIScatterMatrix
from holoviews.streams import Pipe
pn.extension()
os.environ["BOKEH_ALLOW_WS_ORIGIN"] = "*"
class sample():
def __init__(self, col, executor):
self.col = col
self.executor = executor
def start_thread(self):
# self.create_map()
self.executor.submit(self.create_map)
@pn.io.with_lock
def rect(self, i):
rect = hv.Rectangles([(1,1,2,4)])
if i%2:
rect.opts(color="red")
else:
rect.opts(color="black")
self.col.insert(i, rect)
def create_map(self):
try:
start = time.time()
self.col.clear()
for i in range(30):
self.rect(i)
# time.sleep(1)
print("added")
print("time taken", time.time()-start)
except Exception as e:
self.col.clear()
self.col.append(''.join(tb.format_exception(None, e, e.__traceback__)))
raise(e)
executor = ThreadPoolExecutor(max_workers=4)
def create_app():
try:
col = pn.Column(pn.Spacer(sizing_mode="stretch_height"),
pn.Row(
pn.Spacer(sizing_mode="stretch_width"),
pn.widgets.LoadingSpinner(align="center", value=True, height=45, width=45, color='primary'),
pn.Spacer(sizing_mode="stretch_width"),
sizing_mode="stretch_both"
),
pn.Spacer(sizing_mode="stretch_height"),
sizing_mode="stretch_both",
)
# asyncio.create_task(async_create(col, pn.state.curdoc.session_context.id))
sam = sample(col,executor)
sam.start_thread()
print("col***")
return col
except Exception as e:
raise(e)
def main():
#num_procs=4
# ,
pn.serve({"/wafermap" : create_app},
port= 5007,
websocket_origin= "0.0.0.0",
allow_websocket_origin=['*'],
rest_session_info=True,
autoreload=True,
show=False,
admin=True,
session_expiration_duration = 900000,
session_token_expiration = 900000,
unused_session_lifetime = 6000,
check_unused_sessions_milliseconds = 1000,
global_loading_spinner = True
)
if __name__ == "__main__":
main()