Skip to content

Function Pickling: 'NoneType' has no attribute __bool__ #2291

@jamesstidard

Description

@jamesstidard

The seems to be a issue with distributed being able to pickle functions with certain type hints (Union & Optional from my usage).

Here's an example:

from typing import Optional
from distributed import Client

def f2() -> Optional[int]:
    return 1

def f1() -> int:
    return 1

def main():
    client = Client()
    print(client.submit(f1).result())  # works. prints 1
    print(client.submit(f2).result())  # fail. raises
    client.close()

if __name__ == '__main__':
    main()
distributed.worker - WARNING - Could not deserialize task
Traceback (most recent call last):
  File ".../distributed/worker.py", line 1385, in add_task
    self.tasks[key] = _deserialize(function, args, kwargs, task)
  File ".../distributed/worker.py", line 801, in _deserialize
    function = pickle.loads(function)
  File ".../distributed/protocol/pickle.py", line 59, in loads
    return pickle.loads(x)
AttributeError: type object 'NoneType' has no attribute '__bool__'
Traceback (most recent call last):
  File ".../scratches/scratch_7.py", line 22, in <module>
    main()
  File ".../scratches/scratch_7.py", line 17, in main
    print(client.submit(f2).result())
  File ".../distributed/client.py", line 195, in result
    six.reraise(*result)
  File ".../six.py", line 692, in reraise
    raise value.with_traceback(tb)
  File ".../distributed/protocol/pickle.py", line 59, in loads
    return pickle.loads(x)
AttributeError: type object 'NoneType' has no attribute '__bool__'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions