An elegant way to exchange variables between a Windows form and Python Script. Working in the background.

I am trying to find an elegant way to exchange a variable between an application form window and a python script running in the background. This variable will only be used to update the progress bar in the form of a window based on a long running process on a python script. More specifically, a Windows timer starts n every second , checks for a variable, and then updates the progress bar. Is the sound dumb enough? I will try to explain the need for this below.

I have a Windows application that allows the user to define several parameters in order to bring down a lengthy process (python script). Without going into unnecessary details, this long-term process for a considerable period of time inserts a lot (100k + records) into the sqlite database. To make the python script as possible as possible, I don't call commit in the sqlite database until the very end of the python script. Trying to query the sqlite database from a Windows application (via System.Data.Sqlite) before committing always yields 0 records, regardless of how far the process has come.

A Windows application will know how many records will be inserted by the python process, so determining progress will be quite simple, assuming that I can access the record count in a python script.

I know I can do this with a text file, but is there a better way?

+3
source share
2 answers

The simplest solution is probably just to make a python script print to stdout: say, every time an element is processed, print a line with a number representing how many elements have been processed (or percentage). Then the forms application should read the output line, updating the progress bar based on this information.

+1
source

If you use IronPython , you can create a Form-with-progress-bar panel in Python and manipulate it directly.

Alternatively, your Winforms application can host a script and exchange variables.

0
source

Source: https://habr.com/ru/post/1792813/


All Articles