python-3.4

Should I use two asyncio event loops in one program?

给你一囗甜甜゛ 提交于 2019-11-29 07:32:57
问题 I want use the Python 3 asyncio module to create a server application. I use a main event loop to listen to the network, and when new data is received it will do some compute and send the result to the client. Does 'do some compute' need a new event loop? or can it use the main event loop? 回答1: You can do the compute work in the main event loop, but the whole event loop will be blocked while that happens - no other requests can be served, and anything else you have running in the event loop

How to detect exceptions in concurrent.futures in Python3?

给你一囗甜甜゛ 提交于 2019-11-29 06:49:38
I have just moved on to python3 as a result of its concurrent futures module. I was wondering if I could get it to detect errors. I want to use concurrent futures to parallel program, if there are more efficent modules please let me know. I do not like multiprocessing as it is too complicated and not much documentation is out. It would be great however if someone could write a Hello World without classes only functions using multiprocessing to parallel compute so that it is easy to understand. Here is a simple script: from concurrent.futures import ThreadPoolExecutor def pri(): print("Hello

Compiler problems with pip during numpy install under Windows 8.1, 7 Enterprise and 7 Home Editions

淺唱寂寞╮ 提交于 2019-11-29 06:02:00
问题 I am unable to install numpy via pip install numpy on my computer running Python 3.4 due to various errors I receive linked to compilation issues (This is only the case on a 64-bit installation of Python). This is a problem that has been reported extensively and I had a related question about unable to find vcvarsall.bat. I have tested this on three different clean machines running Windows 8.1, 7 Enterprise and 7 Home Editions and it always comes up. Installing Visual Studio 2010 Express C++

python import multiple times

二次信任 提交于 2019-11-29 04:19:57
I suppose this is a general question so sorry if not posted in the right place. Say for instance, I have a function a which imports os . If I was to call this function from another file multiple times I am assuming that the import would be done multiple times as well? Is there a way to only import the module if its not already present? Basically, I have a class which calls multiple functions imported from various files, instead of importing the whole file I thought it would be easier to import just the function but now I am wondering if I am going to give myself headaches in the long run with

Difference in package importing between Python 2.7 and 3.4

倖福魔咒の 提交于 2019-11-29 03:47:42
For this directory hierarchy: . ├── hello │ ├── __init__.py │ └── world │ └── __init__.py └── test.py And the Python source files: test.py: if __name__ == '__main__': import hello hello/__init__.py: import world hello/world/__init__.py: print("yes you win") Running test.py with Python 3.4 throws ImportError saying that module world is not found, but with Python 2.7 everything is fine. I know that sys.path is referenced when searching for the imported modules, so adding the directory hello to sys.path eliminates the error. But in Python 2.7, before importing world , the directory hello is not

error: command 'x86_64-linux-gnu-gcc' when installing mysqlclient

☆樱花仙子☆ 提交于 2019-11-29 03:01:01
问题 I installed django 1.8.5 in virtualenv and using python 3.4.3 the worked displayed the it works page when using sqlite I wanted to use mysql and I'm trying to install mysqlclient using pip install mysqlclient and I'm getting the following message ---------------------------------------- Failed building wheel for mysqlclient Failed to build mysqlclient Installing collected packages: mysqlclient Running setup.py install for mysqlclient Complete output from command /home/sasidhar/django/env/bin

Is it possible to override __new__ in an enum to parse strings to an instance?

喜夏-厌秋 提交于 2019-11-29 00:05:49
I want to parse strings into python enums. Normally one would implement a parse method to do so. A few days ago I spotted the __new__ method which is capable of returning different instances based on a given parameter. Here my code, which will not work: import enum class Types(enum.Enum): Unknown = 0 Source = 1 NetList = 2 def __new__(cls, value): if (value == "src"): return Types.Source # elif (value == "nl"): return Types.NetList # else: raise Exception() def __str__(self): if (self == Types.Unknown): return "??" elif (self == Types.Source): return "src" elif (self == Types.NetList): return

Python 3.4 and 2.7: Cannot install numpy package for python 3.4

三世轮回 提交于 2019-11-28 21:07:32
I am using Ubuntu 12.04 and want to use python 3.4 side by side with python 2.7. The installation of python 3.4 worked properly. However, I cannot install the numpy package for python 3 (and as a consequence I can't install scipy, pandas etc.). Using sudo pip3 install numpy spits out the following error: File "numpy/core/setup.py", line 289, in check_types "Cannot compile 'Python.h'. Perhaps you need to "\ SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel. Btw, I already have python-dev installed. Moreover, installing numpy via sudo apt-get install

What's the correct way to clean up after an interrupted event loop?

你离开我真会死。 提交于 2019-11-28 20:06:52
I have an event loop that runs some co-routines as part of a command line tool. The user may interrupt the tool with the usual Ctrl + C , at which point I want to clean up properly after the interrupted event loop. Here's what I tried. import asyncio @asyncio.coroutine def shleepy_time(seconds): print("Shleeping for {s} seconds...".format(s=seconds)) yield from asyncio.sleep(seconds) if __name__ == '__main__': loop = asyncio.get_event_loop() # Side note: Apparently, async() will be deprecated in 3.4.4. # See: https://docs.python.org/3.4/library/asyncio-task.html#asyncio.async tasks = [ asyncio

Solving install issues with Python 3.4 on Windows

家住魔仙堡 提交于 2019-11-28 18:39:27
问题 I have recently tried to install Python 3.4 as an alternative installation on my system in an attempt to familiarise myself before migrating code. My main Python installation is 2.7.6. I tried the 64 bit installer for Windows, but it came up with an error message There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. After this the install is rolled back (from the point shown