Skip to content

Instantly share code, notes, and snippets.

@TheMatt2
Last active July 12, 2018 15:37
Show Gist options
  • Save TheMatt2/e75353aaa3006ee9d1711f9f1a32cc92 to your computer and use it in GitHub Desktop.
Save TheMatt2/e75353aaa3006ee9d1711f9f1a32cc92 to your computer and use it in GitHub Desktop.
A test program to show some oddity's of multiprocessing.pool behavior.
#************ WARNING, this script can create rouge python instances that need to be manually killed. **************
from Tkinter import *
from multiprocessing import Pool
import time
def myfunc(x):
## window = Tk() # Adding this code causes a crash (loudly and I can not explain.)
## lbl = Label(window, text="Thread %d" % x)
## lbl.grid(column=0, row=0)
## window.mainloop()
time.sleep(1)
return x*x
window = Tk()
lbl = Label(window, text="Main")
lbl.grid(column=0, row=0)
window.mainloop()
pool = Pool(processes = 4) #Crashes here in IDLE
resultlist = pool.map(myfunc, range(10))
pool.close()
print(resultlist)
#************ WARNING, this script can create rouge python instances that need to be manually killed. **************
MacOSX:Desktop user$ python2 -V
Python 2.7.15
MacOSX:Desktop user$ python2 -i pool_test.py
Main
Created main process, press the 'X' to continue.
'X' pressed continuing...
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
>>> exit()
MacOSX:Desktop user$ python2
Python 2.7.15 (default, Jun 17 2018, 12:46:58)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pool_test
Main
Created main process, press the 'X' to continue.
'X' pressed continuing...
^CProcess PoolWorker-2:
Process PoolWorker-4:
Process PoolWorker-3:
Traceback (most recent call last):
Traceback (most recent call last):
Process PoolWorker-1:
Traceback (most recent call last):
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 267, in _bootstrap
Traceback (most recent call last):
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 267, in _bootstrap
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 267, in _bootstrap
self.run()
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 114, in run
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 267, in _bootstrap
self.run()
self.run()
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 114, in run
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
self._target(*self._args, **self._kwargs)
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 102, in worker
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 102, in worker
task = get()
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.py", line 376, in get
task = get()
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.py", line 374, in get
return recv()
racquire()
KeyboardInterrupt
KeyboardInterrupt
self._target(*self._args, **self._kwargs)
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 102, in worker
task = get()
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.py", line 374, in get
self.run()
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 114, in run
racquire()
self._target(*self._args, **self._kwargs)
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 102, in worker
KeyboardInterrupt
task = get()
File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.py", line 374, in get
racquire()
KeyboardInterrupt
^Z
[1]+ Stopped python2
MacOSX:Desktop user$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment