Python 3.5 async/await with real code example

If a third-party library is not compatible with async/await then obviously you can’t use it easily. There are two cases: Let’s say that the function in the library is asynchronous and it gives you a callback, e.g. def fn(…, clb): … So you can do: def on_result(…): … fn(…, on_result) In that case you can … Read more

Did something about `namedtuple` change in 3.5.1?

Per Python bug #24931: [__dict__] disappeared because it was fundamentally broken in Python 3, so it had to be removed. Providing __dict__ broke subclassing and produced odd behaviors. Revision that made the change Specifically, subclasses without __slots__ defined would behave weirdly: >>> Cluster = namedtuple(‘Cluster’, ‘x y’) >>> class Cluster2(Cluster): pass >>> vars(Cluster(1,2)) OrderedDict([(‘x’, 1), … Read more

What is the difference between ProcessPoolExecutor and ThreadPoolExecutor?

ProcessPoolExecutor runs each of your workers in its own separate child process. ThreadPoolExecutor runs each of your workers in separate threads within the main process. The Global Interpreter Lock (GIL) doesn’t just lock a variable or function; it locks the entire interpreter. This means that every builtin operation, including things like listodicts[3][‘spam’] = eggs, is … Read more

AttributeError: module ‘urllib’ has no attribute ‘parse’

The urllib package serves as a namespace only. There are other modules under urllib like request and parse. For optimization importing urllib doesn’t import other modules under it. Because doing so would consume processor cycles and memory, but people may not need those other modules. Individual modules under urllib must be imported separately depending on … Read more

Test if function or method is normal or asynchronous

Use the inspect module of Python. inspect.iscoroutinefunction(object) Return true if the object is a coroutine function (a function defined with an async def syntax). This function is available since Python 3.5. The module is available for Python 2 with lesser functionalities and certainly without the one you are looking for: inspect Inspect module as the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)