File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change 1818logger = logging .getLogger (__name__ )
1919
2020
21+ def apoptosis ():
22+ """Tell the operating system to kill us. This is useful in case we cannot
23+ die. For example, a child thread might refuse to die.
24+ """
25+ import os
26+
27+ # Windows option
28+ if os .name == "nt" :
29+ import subprocess
30+
31+ subprocess .run (["taskkill" , "/IM" , str (os .getpid ()), "/F" ])
32+ # *Nix option
33+ else :
34+ os .kill (os .getpid (), signal .SIGKILL )
35+
36+
2137def resource_path (relative_path ):
2238 """Find a resource in a PyInstaller executable, or in the local directory"""
2339 if hasattr (sys , "_MEIPASS" ):
@@ -407,11 +423,9 @@ def main():
407423 # asyncio task that is hogging the CPU and not surrending control
408424 # via await.
409425 logger .warning ("Failed to stop event thread." )
410- # Since asyncio is not behaving, we need to kill ourselves.
411- if os .name == "nt" :
412- subprocess .run (["taskkill" , "/IM" , str (os .getpid ()), "/F" ])
413- else :
414- os .kill (os .getpid (), signal .SIGKILL )
426+ # Since asyncio is not behaving, we need the operating system to
427+ # end this process
428+ apoptosis ()
415429
416430
417431if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments