streamlit

Форк
0
/
st_exception.py 
57 строк · 2.4 Кб
1
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
import streamlit as st
16
from streamlit.errors import StreamlitAPIException
17

18
e = RuntimeError("This exception message is awesome!")
19
st.exception(e)
20

21
e = StreamlitAPIException(
22
    """
23
Cannot hash object of type `_thread.lock`, found in the return value of
24
`get_data()`.
25

26
While caching the return value of `get_data()`, Streamlit encountered an
27
object of type `_thread.lock`, which it does not know how to hash.
28

29
To address this, please try helping Streamlit understand how to hash that type
30
by passing the `hash_funcs` argument into `@st.cache`. For example:
31

32
```
33
@st.cache(hash_funcs={_thread.lock: my_hash_func_that_is_some_riduculously_long_name})
34
def my_func(...):
35
    ...
36
```
37

38
If you don't know where the object of type  `_thread.lock` is coming
39
from, try looking at the hash chain below for an object that you do recognize,
40
then pass that to `hash_funcs` instead:
41

42
```
43
Object of type _thread.lock: <unlocked _thread.lock object at 0x1392ad690>
44
Object of type builtins.tuple: ('I am another ridiculously long string that will take up space', <unlocked _thread.lock object at 0x1392ad690>)
45
Object of type builtins.dict: {'I am another ridiculously long string that will take up space': <unlocked _thread.lock object at 0x1392ad690>}
46
Object of type builtins.tuple: ('I am a ridiculously long string that will take up space', {'I am another ridiculously long string that will take up space': <unlocked _thread.lock object at 0x1392ad690>})
47
Object of type builtins.dict: {'I am a ridiculously long string that will take up space': {'I am another ridiculously long string that will take up space': <unlocked _thread.lock object at 0x1392ad690>}}
48

49
```
50

51
Please see the `hash_funcs` [documentation](https://docs.streamlit.io/library/advanced-features/caching#the-hash_funcs-parameter)
52
for more details.
53
            """.strip(
54
        "\n"
55
    )
56
)
57
st.exception(e)
58

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.