Chainlit / chainlit

Build Conversational AI in minutes ⚡️
https://docs.chainlit.io
Apache License 2.0
6.67k stars 860 forks source link

Long running exec inside on_message #441

Closed rtu-dataframe closed 11 months ago

rtu-dataframe commented 11 months ago

Hi, i'm using an exec function when a message is received in order to execute some code.

Many times, the code execution needs time (even 5 minutes) and i will get on chainlit ui "Could not reach the server." error message.

So, i've tried to use the make_async function in this way:

has_code, code = await cl.make_async(interpret_code)(gpt_response)

The function block "intepret code", contains these lines of code:

def interpret_code(gpt_response):
    exec(gpt_response)

Please, note that the executed code will need to access a global variable of a defined pandas dataframe defined in the "on_settings_update" code.

However, when the the method is called i get this error message: Python[85675:4320699] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalid

How i can solve this issue?

rtu-dataframe commented 11 months ago

Sorry for the dumb question, it was matplotlib that when a thread is spawned needs to be istantiated via non-interactive backend:

import matplotlib matplotlib.use('agg')