Error in browser but not in code

I am trying to built a streamlit app to control a device. My code calls the functions that connect to the device and outputs the values it gives. It connects to the device with a python-c library. In my code everything runs fine but in my app I get errors (the error is Device already open).
What happens between my code and the app that can cause this problem?
BTW I tried to use cache but then it doesn’t connect to the device.

Thank you for helping

Could you provide the code or some kind of error log?

I am working with- GitHub - vasoto/pycaenhv: Pure Python bindings for CAEN HV Wrapper .
The errors are written in inside pycaenhv/src. It gets errors from the machine, in it translates it to python. The functions are inside whenever I call init_system it opens the machine. in my code I call it once but use the output multiple times and it is fine but in the streamlit app it gives “Device already open”. I think the problem is between my code and the app. how does streamlit executes the code? maybe it calls init_system again?

Adding my code if it will help.
Thank you for responding!

import streamlit as st
import pandas as pd
from ctypes import byref, c_int, c_char_p, POINTER, c_void_p
from _lib import load_lib
from _export_func import export_func
from constants import MAX_CH_NAME
from errors import check_function_output
from typing import List, Union, Any, Optional, Dict
from enums import CAENHV_SYSTEM_TYPE, LinkType

c_int_p = POINTER(c_int)
lib = load_lib()
NamesArrayType = P(c_char_p * MAX_CH_NAME)

CAENHV_InitSystem = export_func(
lib, ‘CAENHV_InitSystem’, c_int,
[c_int, c_int, c_void_p, c_char_p, c_char_p, c_int_p],
‘Initialize HV system’)

def init_system(system_type: Union[CAENHV_SYSTEM_TYPE, int],
link_type: Union[LinkType, int],
argument: Any,
username: str = ‘’,
password: str = ‘’) → int:
“”" Initialize the system and returns the handle
_handle = c_int()
_system = int(system_type)
link = int(link_type)
arg = argument
if isinstance(arg, str):
arg = arg.encode()
err = CAENHV_InitSystem(_system, link, arg, username.encode(),
password.encode(), byref(_handle))
print(‘err’ , err)
return _handle.value

st.title(“CAEN app”)
h = int(init_system(2, 0, ‘’, ‘admin’, ‘admin’)) #this is where it gets stuck

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.