Script = good, but crashes when used with Streamlit (something to do with win32com)

Hi all,
I am a 1 week user of Streamlit and loving it thus far. Please may I outline my issue and question.

I have written a script that uses multiple win32com Dispatch calls which works perfectly in Spyder (note this is a work project which interfaces with an old software, and I cannot share the code :frowning: )

When I run in Streamlit the whole thing freezes. If I ctrl + c in the terminal it says stopping but never does. The part where it freezes is a backend Dispatch call.

I am wondering if there is a way to run the streamlit front end on one thread and the backend (script) on another thread, and if this will help me?

If it is possible, is there a simple guide? (I am a data analyst, not a programmer).

Thank you!

To add a little bit…It almost “feels” like Streamlit is blocking the win32com Dispatch call, so the program just sits there.
This is why I wondered if I could run the Dispatch calls on a different thread.

Hi @LukeF,

Could you share the error / traceback at least?

If you’re using Windows 10 it might have something to do with Windows Defender and “remote code execution” since you’re not calling win32com Dispatch directly but via the tornado webserver. I’ve had a similar problem with win32com and Excel sheets when trying to run them via a webserver as a service. Workaround at the time was to turn off “real-time protection”.

2 Likes

Ah very interesting, thank you.

So that is the thing, there is no error per se, nothing printed in the terminal. The program just gets stuck when it tries to access the Dispatch call. The web front end continues to say “Running”, the terminal just sits there sucking it’s thumb.

Is there a way to see “hidden” error messages?

Thank you for replying :slight_smile:

Ah yes you said there was no error message, forgot that while is was typing my reply :slight_smile:

You could try running the app in debug mode and put a breakpoints before and after the Dispatch call.

2 Likes

Thank you, nice idea!

I will do this tomorrow at work and report on any success/failures!

Hello again,
So after some debugging today I realised that the COM module works for most Dispatch calls, but not with the call that I make to our internal software.
I think you may be correct @maarten-betman that the software I am using does not like being called by the Tornado server.

But happily I can report that I found a work-around!
I used the python module “subprocess”.

So Streamlit handles the front end + the logic, inputs, then I pass the inputs to another python script which runs as a subprocess in another terminal.
This works perfectly and I am excited to show my boss tomorrow!

Thank you for the helpful advice and encouragement!

4 Likes