How do I keep a GUI alive during a long-running subprocess?

This wiki is in the process of being archived due to lack of usage and the resources necessary to serve it — predominately to bots, crawlers, and LLM companies. Edits are discouraged.
Pages are preserved as they were at the time of archival. For current information, please visit python.org.
If a change to this archive is absolutely needed, requests can be made via the infrastructure@python.org mailing list.

This frequently-asked question appears, for example, in this Usenet posting. No single answer is canonical, for each has definite liabilities and limitations; there are, however, a number of expedients which apply in at least some situations:

  • "fire and forget", that is, put the subprocess in the background and let it run freely;

  • put the subprocess in the background, return to the GUI's event loop, and poll to detect when the subprocess has terminated;
  • put the subprocess in its own thread, and rely on Python ThreadProgramming ...;

  • launch subprocess.Popen() in a conventional way, but interleave attention in a single thread of control between the GUI controller and the stdout from the subprocess.

  • the particular GUI framework involved--wxPython, TkInter, probably has specific mechanisms for managing concurrency in an event-based way. The toolkit behind Tkinter, in fact, already has a Wiki page on the subject above, many of whose hints can be adapted to other frameworks;

  • ...

[links, explanations, warnings]


2026年02月14日 16:09

AltStyle によって変換されたページ (->オリジナル) /