This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: contextvars.Context.run hangs forever in ProccessPoolExecutor
Type: behavior Stage:
Components: Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ronserruya, yselivanov
Priority: normal Keywords:

Created on 2020-01-08 10:34 by ronserruya, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg359575 - (view) Author: Ron Serruya (ronserruya) Date: 2020-01-08 10:34
Sending Context.run to another process via ProccessPoolExecutor hangs forever:

```
from contextvars import ContextVar, copy_context
from concurrent.futures import ProcessPoolExecutor
from multiprocessing import Process

var: ContextVar[int] = ContextVar('var',default=None)

if __name__ == '__main__':
    
    # ***** This hangs forever *****
    with ProcessPoolExecutor(max_workers=1) as pp:
        ctx = copy_context()
        pp.submit(ctx.run, list)

    # ****** This throws 'cannot pickle Context' # ***** This hangs forever *****
    ctx = copy_context()
    p = Process(target=ctx.run, args=(list,))
    p.start()
    p.join()
```

python version is 3.8.0
running on Mac OSX 10.15.1
msg359749 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2020-01-10 19:23
> This throws 'cannot pickle Context' 

Yes, this is expected. contextvars are not compatible with multiprocessing.

> **** This hangs forever *****

This hanging part is weird, and most likely hints at a bug in multiprocessing.
History
Date User Action Args
2022-04-11 14:59:25adminsetgithub: 83438
2020-01-10 19:23:50yselivanovsetmessages: + msg359749
2020-01-10 19:17:18asvetlovsetmessages: - msg359576
2020-01-08 11:06:36xtreaksetnosy: + yselivanov
2020-01-08 10:37:29ronserruyasetmessages: + msg359576
2020-01-08 10:34:34ronserruyacreate