• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to stop a thread that has a blocking function from easygui in python

Resolved: How to stop a thread that has a blocking function from easygui in python

0
By Isaac Tonny on 05/04/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve How to stop a thread that has a blocking function from easygui in python

Question:

Context


I am using the easygui library to make a simple interface for my program.
In the program, I need to start a process that takes time and the user can cancel it if he is tired of waiting.

Code


Here is a minimal example code:

The goal


I want to close the msgbox if the connection is successful and the user never clicked ok to cancel the connection.

The problem


The problem is that if the user never clicks ok, the msgbox will never return and the code will never reach any line after the msgbox line.
So I can’t even add a flag to the end_connection function because there will never be a chance for the function to check it.

Main question


How can I kill this monitor_thread “gracefully”?
Or, is there another way to achieve the desired result?

Outro


Let me know if you need more code or information to understand something. The actual code has a lot of unnecessary things that may draw attention from the actual problem.

Best Answer:

You could use the multiprocessing module instead of threading because it allow you to terminate a process whereas thread dont do it properly.
Here is the modified code:

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

easygui multithreading python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Removing null keys from a json array of objects

05/04/2023

Resolved: How can I generate at compile-time a separate OpenAPI Swagger.json file for each Controller in my ASP.NET project?

05/04/2023

Resolved: Error No file found while converting file present in s3 using boto3

04/04/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.