2

I'm getting the error TypeError: 'NoneType' object is not callable in self.pool.join called by the __del__ method of a module containing the following code.

In particular, the error occurs when running database migrations or the test suite in a Django application.

I've tried implementing import atexit and registering the methods inside __init__ via:

atexit.register(self.pool.close)
atexit.register(self.pool.join)

...but this hasn't worked.

Why is this TypeError occuring in the code below's __del__ method, and how can I avoid it?

import datetime
import json
import mimetypes
from multiprocessing.pool import ThreadPool
import os
import re
import tempfile

# python 2 and python 3 compatibility library
import six
from six.moves.urllib.parse import quote

from paapi5_python_sdk.configuration import Configuration
import paapi5_python_sdk
from paapi5_python_sdk import rest

from paapi5_python_sdk.auth.sig_v4 import AWSV4Auth

class ApiClient(object):
    PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types
    NATIVE_TYPES_MAPPING = {
        'int': int,
        'long': int if six.PY3 else long,  # noqa: F821
        'float': float,
        'str': str,
        'bool': bool,
        'date': datetime.date,
        'datetime': datetime.datetime,
        'object': object,
    }

    def __init__(self,
                 access_key,
                 secret_key,
                 host,
                 region,
                 configuration=None,
                 header_name=None,
                 header_value=None,
                 cookie=None):
        if configuration is None:
            configuration = Configuration()
        self.configuration = configuration

        self.pool = ThreadPool()
        self.rest_client = rest.RESTClientObject(configuration)
        self.default_headers = {}
        if header_name is not None:
            self.default_headers[header_name] = header_value
        self.cookie = cookie
        # Set default User-Agent.
        self.user_agent = 'paapi5-python-sdk/1.0.0'

        self.access_key = access_key
        self.secret_key = secret_key
        self.host = host
        self.region = region

    def __del__(self):
        self.pool.close()
        self.pool.join()

    ... rest of module
YPCrumble
  • 26,610
  • 23
  • 107
  • 172
  • can you show some example code of how you are causing this behavior to happen. also as a side note having behavior happen in `__del__` is not advised. please look at this [question](https://stackoverflow.com/a/1481512/6817835) – gold_cy Mar 14 '20 at 15:33

0 Answers0