Skip to content
Advertisement

Mocking async call in python 3.5

How do I mock async call from one native coroutine to other one using unittest.mock.patch? I currently have quite an awkward solution: Then This works but looks ugly. Is there more pythonic way to do this? Answer The solution was actually quite simple: I just needed to convert __call__ method of mock into coroutine: This works perfectly, when mock is

PyCharm asks for python interpreter every time project is loaded

Rather frustratingly, every time I load up an existing project or create a new one – it complains there is no interpreter selected and I have to provide the path to it. There is nothing unusual about my python installation, it’s sat in C:/Python27/ as you would expect. It always used to work, but the last few weeks something has

Iterating through pandas groupby groups

I have a pandas dataframe school_df that looks like this: Each row represents one project by that school. I’d like to add two columns: for each unique school_id, a count of how many projects were posted before that date and a count of how many projects were completed before that date. The code below works, but I have ~300,000 unique

How to get form POST input in Tornado?

I amd new to Tornado framework and trying to make a simple form to upload images: I can successfully receive the Posted file using: However I’m unable to receive the alt input. I tried alt = self.request.alt but I get this error and when I use alt = self.request.files[‘alt’], I get: I ran out of ideas so appreciate your help.

Logging module not working with Python3

I am having issues with the standard logging module. If I open a python2.7 shell and import logging everything works fine: But if I open a python3.4 shell and import logging I get the following error: I have no idea what the problem is and can’t seem to find anyone else who has had the same issue. Answer You seem

QtConcurrent in PySide/PyQt

I’m trying to figure out if subclassing QtConcurrent and writing a run method inside it will work: Or is it completely useless? Answer It’s completely useless, because QtConcurrent is a namespace, not a class. Also, neither PyQt nor PySide provide any of the functionality provided by QtConcurrent, because it’s all template-based and therefore impossible to wrap. PS: the PySide documentation

celery doesn’t work with global variable

this is the code I used to test celery. I hope every time I use addone() the return value should increase. But it’s always 1 why??? Results Answer By default when a worker is started Celery starts it with a concurrency of 4, which means it has 4 processes started to handle task requests. (Plus a process that controls the

Advertisement