python-3.4

Why can't I catch SIGINT when asyncio event loop is running?

守給你的承諾、 提交于 2020-01-01 08:22:11
问题 Using Python 3.4.1 on Windows, I've found that while executing an asyncio event loop, my program can't be interrupted (i.e. by pressing Ctrl+C in the terminal). More to the point, the SIGINT signal is ignored. Conversely, I've determined that SIGINT is handled when not in an event loop. Why is it that SIGINT is ignored when executing an asyncio event loop? The below program should demonstrate the problem - run it in the terminal and try to stop it by pressing Ctrl+C, it should keep running:

How do I connect asyncio.coroutines that continually produce and consume data?

大城市里の小女人 提交于 2020-01-01 05:31:12
问题 I am trying to learn how to (idiomatically) use Python 3.4's asyncio . My biggest stumbling block is how to "chain" coroutines that continually consume data, update state with it, and allow that state to be used by another coroutine. The observable behaviour I expect from this example program is simply to periodically report on the sum of numbers received from a subprocess. The reporting should happen at roughly the same rate the Source object recieves numbers from the subprocess. IO blocking

Django 2, python 3.4 cannot decode urlsafe_base64_decode(uidb64)

纵然是瞬间 提交于 2019-12-31 10:39:10
问题 i am trying to activate a user by email, email works, encoding works, i used an approach from django1.11 which was working successfully. In Django 1.11 the following decodes successfully to 28, where uidb64 = b'Mjg' force_text(urlsafe_base64_decode(uidb64)) In django 2 (2, 0, 0, 'final', 0) the above code decode does not work and results in an error django.utils.encoding.DjangoUnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 1: invalid continuation byte. You passed in b'l

Python `for` does not iterate over enumerate object

梦想的初衷 提交于 2019-12-31 05:26:30
问题 Why does this not iterate? import logging logging.basicConfig(level=logging.DEBUG) x = [] y = [[] for n in range(0, 1)] linedata = ["0","1","2"] x.append( linedata[0] ) d = linedata[1:] logging.debug( "d: {}".format(d) ) e = enumerate(d) logging.debug( list(e) ) for k, v in e: logging.debug( "k:{} v:{}".format( k, v ) ) y[int(k)].append( v ) #for d in [(0,1)]: #logging.debug( "k:{} v:{}".format( d[0], d[1] ) ) #y[d[0]].append( d[1] ) logging.debug( x ) logging.debug( y ) Output: DEBUG:root:d:

`python -m ensurepip --upgrade` does not seem to be upgrading pip and setuptools

不打扰是莪最后的温柔 提交于 2019-12-31 02:48:09
问题 I am on a Mac running Yosemite (Mac OS X 10.10.1) and homebrew installed python and python3 and python -m ensurepip --upgrade does not seem to be working as I would have expected. python -m ensurepip --upgrade does not upgrade pip or setuptools. pip install --upgrade pip setuptools upgrades pip to 6.0.7 and upgrades setuptools to 12.0.5. Same results with Python3. Do I misunderstand the purpose of ensurepip? 回答1: Per the documentation: This module does not access the internet. All of the

Python3 PIL Pillow Ubuntu Install

那年仲夏 提交于 2019-12-31 02:43:14
问题 I'm running Ubuntu 14.04 LTS. I have both Python 2.7 and Python 3.4 installed. I'm relatively novice when it comes to installing Python Packages in Linux. I'm just trying to install and get access to PIL's image library in Python 3.4. It is my understanding that this is achieved by installing Pillow, the modern fork of PIL. It seems in my floundering I managed to successfully get PIL working in Python 2.7, but I still cannot get it working in 3.4. I got pip and pip3 . When I enter sudo pip3

How to import sqlite3 in my python3.4 successfully?

强颜欢笑 提交于 2019-12-31 00:56:09
问题 There are two python version in my debian7, one is python2.7 the system default version, the other is python3.4 which compiled to install this way. apt-get update apt-get upgrade apt-get install build-essential wget http://www.python.org/ftp/python/3.4.0/Python-3.4.0.tgz tar -zxvf Python-3.4.0.tgz cd Python-3.4.0 mkdir /usr/local/python3.4 ./configure --prefix=/usr/local/python3.4 make make install ln -s /usr/local/python3.4/bin/python3.4 /usr/bin/python3.4 ln -s /usr/local/python3.4/bin/pip3

How to list all exceptions a function could raise in Python 3?

余生长醉 提交于 2019-12-30 05:37:08
问题 Is there a programmatic way to get a list of all exceptions a function could raise? I know for example that os.makedirs(path[, mode]) can raise PermissionError (and maybe others), but the documentation only mentions OSError. (This is just an example - maybe even a bad one; I am not especially interested in this function - more in the problem in general). Is there a programmatic way to find all the possible exceptions when they are not/poorly documented? This may be especially useful in 3rd

pyaudio installation on mac (python 3)

流过昼夜 提交于 2019-12-30 00:51:24
问题 I first tried: pip install pyaudio but I was told that -bash: pip: command not found Then I tried: pip3 install pyaudio then i got: src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found #include "portaudio.h" ^ 1 error generated. error: command '/usr/bin/clang' failed with exit status 1 ---------------------------------------- Command "/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 -c "import setuptools, tokenize;__file__='/private/var/folders/77

Python threading self._stop() 'Event' object is not callable

放肆的年华 提交于 2019-12-29 01:41:08
问题 Trying a "stoppable" thread from https://stackoverflow.com/a/325528/1619432 like so: import sys import threading import time import logging class StoppableThread(threading.Thread): """Thread class with a stop() method. The thread itself has to check regularly for the stopped() condition.""" def __init__(self): print( "base init", file=sys.stderr ) super(StoppableThread, self).__init__() self._stop = threading.Event() def stop(self): print( "base stop()", file=sys.stderr ) self._stop.set() def