[issue35629] hang and/or leaked processes with multiprocessing.Pool(...).imap(...)

2019-01-04 Thread STINNER Victor


STINNER Victor  added the comment:

> I'm using `contextlib.closing`

Oh, I missed that: good!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35629] hang and/or leaked processes with multiprocessing.Pool(...).imap(...)

2019-01-04 Thread Anthony Sottile


Anthony Sottile  added the comment:

If you see the bottom of my issue, I've suggested (nearly) the same thing -- 
though I require python2.x compatibility so I'm using `contextlib.closing`

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35629] hang and/or leaked processes with multiprocessing.Pool(...).imap(...)

2019-01-04 Thread STINNER Victor


STINNER Victor  added the comment:

I suggest you to write:

with multiprocessing.Pool(4) as pool: result = tuple(pool.imap(print, (1, 2, 
3)))

On Python 3.8, your example will now log a resource warning since you don't 
close/terminate explicitly the pool.

--
nosy: +vstinner

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35629] hang and/or leaked processes with multiprocessing.Pool(...).imap(...)

2019-01-04 Thread Antoine Pitrou


Antoine Pitrou  added the comment:

Indeed, looks like a duplicate.

--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> multiprocessing.Pool.imaps iterators do not maintain alive the 
multiprocessing.Pool objects

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35629] hang and/or leaked processes with multiprocessing.Pool(...).imap(...)

2019-01-04 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
nosy: +pitrou
versions:  -Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35629] hang and/or leaked processes with multiprocessing.Pool(...).imap(...)

2019-01-02 Thread Rémi Lapeyre

Change by Rémi Lapeyre :


--
nosy: +pablogsal

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35629] hang and/or leaked processes with multiprocessing.Pool(...).imap(...)

2019-01-02 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

I believe that this is similar to https://bugs.python.org/issue35378 on which 
@pablogsal is working.

You were right, the issue steems from a refcount bug. Until the resolution you 
can avoid the issue by explictly keeping a reference on the pool:

>>> import multiprocessing
>>> d = multiprocessing.Pool(4)
>>> tuple(d.imap(print, (1, 2, 3)))
1
2
3
(None, None, None)
>>>

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35629] hang and/or leaked processes with multiprocessing.Pool(...).imap(...)

2018-12-31 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

Weirdly enough, it works with iPython:

$ ipython3
Python 3.7.1 (default, Nov  6 2018, 18:49:54)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import multiprocessing

In [2]: tuple(multiprocessing.Pool(4).imap(print, (1, 2, 3)))
...:
1
2
3
Out[2]: (None, None, None)

In [3]:

--
nosy: +remi.lapeyre

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35629] hang and/or leaked processes with multiprocessing.Pool(...).imap(...)

2018-12-31 Thread Anthony Sottile


New submission from Anthony Sottile :

This simple program causes a hang / leaked processes (easiest to run in an 
interactive shell):

import multiprocessing
tuple(multiprocessing.Pool(4).imap(print, (1, 2, 3)))

$ python3.6
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import multiprocessing
>>> tuple(multiprocessing.Pool(4).imap(print, (1, 2, 3)))
1
2
3
<<>>
^CProcess ForkPoolWorker-1:
Traceback (most recent call last):
Process ForkPoolWorker-2:
Process ForkPoolWorker-3:
Process ForkPoolWorker-4:
  File "/usr/lib/python3.6/multiprocessing/pool.py", line 746, in next
item = self._items.popleft()
IndexError: pop from an empty deque

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.6/multiprocessing/pool.py", line 750, in next
self._cond.wait(timeout)
  File "/usr/lib/python3.6/threading.py", line 295, in wait
waiter.acquire()
KeyboardInterrupt


$ python3.7
Python 3.7.2 (default, Dec 25 2018, 03:50:46) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import multiprocessing
>>> tuple(multiprocessing.Pool(4).imap(print, (1, 2, 3)))
1
2
3
(None, None, None)
>>> 
KeyboardInterrupt
Process ForkPoolWorker-3:
Process ForkPoolWorker-1:
Process ForkPoolWorker-2:
Process ForkPoolWorker-4:
>>> Traceback (most recent call last):
  File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
  File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
Traceback (most recent call last):
  File "/usr/lib/python3.7/multiprocessing/pool.py", line 110, in worker
task = get()
  File "/usr/lib/python3.7/multiprocessing/queues.py", line 351, in get
with self._rlock:
  File "/usr/lib/python3.7/multiprocessing/synchronize.py", line 95, in 
__enter__
return self._semlock.__enter__()
KeyboardInterrupt
  File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
  File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.7/multiprocessing/pool.py", line 110, in worker
task = get()
  File "/usr/lib/python3.7/multiprocessing/queues.py", line 351, in get
with self._rlock:
  File "/usr/lib/python3.7/multiprocessing/synchronize.py", line 95, in 
__enter__
return self._semlock.__enter__()
KeyboardInterrupt
Traceback (most recent call last):
  File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
  File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.7/multiprocessing/pool.py", line 110, in worker
task = get()
  File "/usr/lib/python3.7/multiprocessing/queues.py", line 351, in get
with self._rlock:
  File "/usr/lib/python3.7/multiprocessing/synchronize.py", line 95, in 
__enter__
return self._semlock.__enter__()
KeyboardInterrupt
Traceback (most recent call last):
  File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
  File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.7/multiprocessing/pool.py", line 110, in worker
task = get()
  File "/usr/lib/python3.7/multiprocessing/queues.py", line 352, in get
res = self._reader.recv_bytes()
  File "/usr/lib/python3.7/multiprocessing/connection.py", line 216, in 
recv_bytes
buf = self._recv_bytes(maxlength)
  File "/usr/lib/python3.7/multiprocessing/connection.py", line 407, in 
_recv_bytes
buf = self._recv(4)
  File "/usr/lib/python3.7/multiprocessing/connection.py", line 379, in _recv
chunk = read(handle, remaining)
KeyboardInterrupt


(python3.8 shows the same behaviour as python3.7)
$ ./python --version --version
Python 3.8.0a0 (heads/master:ede0b6fae2, Dec 31 2018, 09:19:17) 
[GCC 7.3.0]


python2.7 also has similar behaviour.

I'm told this more reliably hangs on windows, though I don't have windows on 
hand.

I've "fixed" my code to explicitly open / close the pool:

with contextlib.closing(multiprocessing.Pool(jobs)) as pool:
tuple(pool.imap(...))


I suspect a refcounting / gc bug

--
components: Library (Lib)
messages: 332825
nosy: Anthony Sottile
priority: normal
severity: normal
status: open
title: hang and/or leaked processes with multiprocessing.Pool(...).imap(...)
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/arch