Skip to content

contextvars.Context.run hangs forever in ProccessPoolExecutor #83438

Open

Description

@Ronserruya
mannequin
BPO 39257
Nosy @1st1, @Ronserruya

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-01-08.10:34:34.026>
labels = ['type-bug', '3.8']
title = 'contextvars.Context.run hangs forever in ProccessPoolExecutor'
updated_at = <Date 2020-01-10.19:23:50.063>
user = 'https://github.com/Ronserruya'

bugs.python.org fields:

activity = <Date 2020-01-10.19:23:50.063>
actor = 'yselivanov'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = []
creation = <Date 2020-01-08.10:34:34.026>
creator = 'ronserruya'
dependencies = []
files = []
hgrepos = []
issue_num = 39257
keywords = []
message_count = 2.0
messages = ['359575', '359749']
nosy_count = 2.0
nosy_names = ['yselivanov', 'ronserruya']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue39257'
versions = ['Python 3.8']

Activity

  1. Ronserruya commented on Jan 8, 2020

    Ronserruyamannequin
    MannequinAuthor

    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

  2. 1st1 commented on Jan 10, 2020

    @1st1
    Member

    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.

  3. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions