我想要一个长时间运行的进程来返回它在队列(或类似的东西)上的进度,我将把它提供给进度条对话框.完成该过程后,我还需要结果.这里的测试示例失败了RuntimeError: Queue objects should only be shared between processes through inheritance.
import multiprocessing, time
def task(args):
count = args[0]
queue = args[1]
for i in xrange(count):
queue.put("%d mississippi" % i)
return "Done"
def main():
q = multiprocessing.Queue()
pool = multiprocessing.Pool()
result = pool.map_async(task, [(x, q) for x in range(10)])
time.sleep(1)
while not q.empty():
print q.get()
print result.get()
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
我已经能够得到这个使用单个进程对象的工作(在这里我很 alowed传递一个队列引用),但是我没有一个池来管理许多流程我要启动.有关更好的模式的建议吗?
我正在使用macOS 10.12.1 Sierra.我使用的是Python 2.7.12
brew install python
Run Code Online (Sandbox Code Playgroud)
但是IDLE给出了警告
WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable.
Visit http://www.python.org/download/mac/tcltk/ for current information.
Run Code Online (Sandbox Code Playgroud)
果然,它经常崩溃.8.5.9是macOS预安装版本.
我可以从ActiveState网站下载稳定的8.5.18 (由python推荐,它与python.org的python安装一起工作(因为他们在使用不稳定的macOS默认8.5.9之前寻找任何其他版本的Tcl/Tk) ).
但是这个下载不会影响brew安装的python IDLE,它继续使用8.5.9.
有什么我可以做的事情来链接更新的Tcl/Tk和Homebrew,或者我可以直接用自制软件安装Tcl/Tk吗?
我也注意到使用anaconda python时会出现完全相同的问题,它使用预安装的mac tcl/tk 8.5.9,而不是用户安装的tcl/tk 8.5.18.
假设我在我的pytest.ini文件中禁用了pytest插件,如:
[pytest]
...
addopts=
-p no:myplugin
Run Code Online (Sandbox Code Playgroud)
现在我希望能够使用命令行参数启用它,例如:
pytest -p yes:myplugin
Run Code Online (Sandbox Code Playgroud)
那可能吗?如果您有更好的建议,我也想知道.
I am trying to install pygame for Python 3 on an anaconda install.
I run pip install pygame, and it outputs the following:
Collecting pygame
Using cached pygame-1.9.3.tar.gz
Building wheels for collected packages: pygame
Running setup.py bdist_wheel for pygame ... error
Complete output from command //anaconda/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/s0/514rk5j90q90x4s8n48ry7wc0000gn/T/pip-build-2n_0kk3y/pygame/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /var/folders/s0/514rk5j90q90x4s8n48ry7wc0000gn/T/tmpybu68q2lpip-wheel- --python-tag cp35:
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-10.6-x86_64-3.5
creating build/lib.macosx-10.6-x86_64-3.5/pygame
copying lib/__init__.py -> build/lib.macosx-10.6-x86_64-3.5/pygame
copying lib/_camera_opencv_highgui.py …Run Code Online (Sandbox Code Playgroud) 我正在编写一个库,我可以使用库中的对象构造表达式.例如,x并且y是来自我的库的实例,我可以构造如下表达式:
# below is a simplified version of my class
class MySymbol(object):
import random
_random_value = random.randint(1,4)
def __init__(self, value):
self.value = value
def __add__(self, symbol):
return MySymbol(self.value + symbol.value)
def __mul__(self, symbol):
return MySymbol(self.value * symbol.value)
def __repr__(self):
return str(self.value)
def _get_random_value(self):
return self._random_value
x,y = sympy.symbols('x y')
x = MySymbol(9)
y = MySymbol(3)
import sympy
A = sympy.Matrix([[x,y],[x,y]])
B = sympy.Matrix([[x+y,x*y]])
Run Code Online (Sandbox Code Playgroud)
矩阵运算也是如此.当我希望它们维护它们的类型时,sympy.Matrix该类将这些元素转换为:sympy.core.numbers.IntegerMySymbol
BA=B*A
print type(BA[0,0])
print type(x*x+y*x+x*x*y) # first element …Run Code Online (Sandbox Code Playgroud) 我的任务是编写一个程序,要求用户输入它存储在列表中的5个名称.接下来,它随机选择其中一个名称并宣布该人为胜利者.唯一的问题是,当我尝试运行它时,它说can't assign to literal.
这是我的代码:
import random
1=input("Please enter name 1:")
2=int(input('Please enter name 2:'))
3=int(input('Please enter name 3:'))
4=int(input('Please enter name 4:'))
5=int(input('Please enter name 5:'))
name=random.randint(1,6)
print('Well done '+str(name)+'. You are the winner!')
Run Code Online (Sandbox Code Playgroud)
我必须能够生成一个随机名称.
你如何在Pygame中播放mp4视频?
我试过pygame.movie但这不起作用......
Theres也是moviepy,但我无法更改弹出窗口的标题.它说"MoviePy",不知道如何改变它.
import moviepy
from moviepy.editor import *
import os
os.environ["SDL_VIDEO_CENTERED"] = "1"
clip = VideoFileClip('qq.mp4')
clip.preview()
execfile("qq.py") # Execute my game right after the clip shows
Run Code Online (Sandbox Code Playgroud)
如何将标题从"MoviePy"更改为"我的游戏名称"
任何帮助,将不胜感激!
在阅读从SQL数据库到pandas数据帧的大关系时,有一个进度条会很好,因为元组的数量是静态已知的,并且可以估计I/O速率.看起来该tqdm模块具有一个函数tqdm_pandas,该函数将报告映射函数在列上的进度,但默认情况下调用它不会像这样报告I/O上的进度.是否可以tqdm在通话中使用进度条pd.read_sql?
说我有一个这样定义的函数:
def inner_func(spam, eggs):
# code
Run Code Online (Sandbox Code Playgroud)
然后,我想调用这样的函数:
outer_func(spam=45, eggs="blah")
Run Code Online (Sandbox Code Playgroud)
在内部,outer_func我希望能够inner_func使用与传入的参数完全相同的参数进行调用outer_func。
可以这样编写outer_func:
def outer_func(spam, eggs):
inner_func(spam, eggs)
Run Code Online (Sandbox Code Playgroud)
但是,我希望能够更改参数inner_func接受,并相应地更改传递给我的参数outer_func,而不必outer_func每次都更改任何内容。
有(简便)方法可以做到这一点吗?请使用Python 3。
我已经在 moviepy 和 ffmpeg 中研究过这个,但只能找到如何旋转视频,而不是水平翻转它。