Skip to content

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

Closed

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__'

Activity

  1. martindurant commented on Oct 5, 2018

    @martindurant
    Member

    From distributed's point of view, the type hints will not get used, since the point of pickling is to execute only. I wonder if there's a single way to strip the type information before pickling.

  2. mrocklin commented on Oct 5, 2018

    @mrocklin
    Member

    Dask relies on cloudpickle for function serialization. I recommend asking questions there.

    For this particular question it may have already come up and been resolved. See cloudpipe/cloudpickle#193 . It looks like there hasn't been a release since then though. You could try on cloudpickle master and, if that doesn't work, raise a new issue at https://github.com/cloudpipe/cloudpickle/issues/new

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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