在这里,我们将给大家分享关于Python2.x-Windows上毫秒级的睡眠调用的知识,让您更了解python休眠毫秒的本质,同时也会涉及到如何更有效地64位Windows上的NumPyforPyth
在这里,我们将给大家分享关于Python 2.x-Windows上毫秒级的睡眠调用的知识,让您更了解python休眠毫秒的本质,同时也会涉及到如何更有效地64位Windows上的NumPy for Python 2.7、Pycharm连接windows上python、Python 3.3.2 – 如何在Windows上运行脚本、python – Windows上的os.stat()的内容。
本文目录一览:- Python 2.x-Windows上毫秒级的睡眠调用(python休眠毫秒)
- 64位Windows上的NumPy for Python 2.7
- Pycharm连接windows上python
- Python 3.3.2 – 如何在Windows上运行脚本
- python – Windows上的os.stat()
Python 2.x-Windows上毫秒级的睡眠调用(python休眠毫秒)
在这个论坛上,我得到了关于如何在Python 2中编写时钟对象的一些很好的提示。我现在有一些代码在工作。这是一个时钟,以60 FPS的速度“滴答”:
import sysimport timeclass Clock(object): def __init__(self): self.init_os() self.fps = 60.0 self._tick = 1.0 / self.fps print "TICK", self._tick self.check_min_sleep() self.t = self.timestamp() def init_os(self): if sys.platform == "win32": self.timestamp = time.clock self.wait = time.sleep def timeit(self, f, args): t1 = self.timestamp() f(*args) t2 = self.timestamp() return t2 - t1 def check_min_sleep(self): """checks the min sleep time on the system""" runs = 1000 times = [self.timeit(self.wait, (0.001, )) for n in xrange(runs)] average = sum(times) / runs print "average min sleep time:", round(average, 6) sort = sorted(times) print "fastest, slowest", sort[0], sort[-1] def tick(self): next_tick = self.t + self._tick t = self.timestamp() while t < next_tick: t = self.timestamp() self.t = tif __name__ == "__main__": clock = Clock()
时钟的效果还不错,但是为了避免繁忙的循环,我希望Windows睡眠时间比通常的少15毫秒。在我的系统(64位Windows
10)上,如果Python是唯一正在运行的应用程序,则在启动时钟时,它平均返回大约15/16毫秒。对于最小的睡眠时间来说太长了,无法避免繁忙的循环。
有人知道我怎样才能使Windows的睡眠时间少于该值吗?
答案1
小编典典您可以暂时将计时器周期降低到由wPeriodMin
返回的值timeGetDevCaps
。以下定义了timer_resolution
调用timeBeginPeriod
和timeEndPeriod
函数的上下文管理器。
import timeitimport contextlibimport ctypesfrom ctypes import wintypeswinmm = ctypes.WinDLL(''winmm'')class TIMECAPS(ctypes.Structure): _fields_ = ((''wPeriodMin'', wintypes.UINT), (''wPeriodMax'', wintypes.UINT))def _check_time_err(err, func, args): if err: raise WindowsError(''%s error %d'' % (func.__name__, err)) return argswinmm.timeGetDevCaps.errcheck = _check_time_errwinmm.timeBeginPeriod.errcheck = _check_time_errwinmm.timeEndPeriod.errcheck = _check_time_err@contextlib.contextmanagerdef timer_resolution(msecs=0): caps = TIMECAPS() winmm.timeGetDevCaps(ctypes.byref(caps), ctypes.sizeof(caps)) msecs = min(max(msecs, caps.wPeriodMin), caps.wPeriodMax) winmm.timeBeginPeriod(msecs) yield winmm.timeEndPeriod(msecs)def min_sleep(): setup = ''import time'' stmt = ''time.sleep(0.001)'' return timeit.timeit(stmt, setup, number=1000)
例
>>> min_sleep()15.6137827>>> with timer_resolution(msecs=1): min_sleep()...1.2827173000000016
with
块之后,将恢复原始计时器分辨率:
>>> min_sleep()15.6229814
64位Windows上的NumPy for Python 2.7
我一直试图在Windows 64位上获得NumPy for Python 2.7,但是大家提到的页面 http://www.lfd.uci.edu/~gohlke/pythonlibs/并没有在我的任何设备上打开.
还有其他地方我可以找到吗?
解决方法
07.01由WinPython创建者解释为什么通常很难找到64位Windows NumPy:
According to experienced developers,there is no decent open-source (free) Fortran compiler for the Windows 64bit platform. As a consequence,it’s impossible to build NumPy or SciPy on this platform using only free and open-source tools. That’s why there is no official Windows 64bit binaries for these two libraries. The only ready-to-use installers available out there were prepared by Christoph Gohlke (using Intel Fortran compiler,a.k.a. ‘ifort’) and these are clearly unofficial binaries. Furthermore,Christoph has built two different installers for NumPy: one unoptimized and one optimized with the Intel Math Kernel Library (MKL),hence providing better performance. And Gohlke’s SciPy 64bit binary package (the only one available freely online) require NumPy MKL. The problem is that,according to Christoph Gohlke,the MKL license does not allow me (or anyone else) to redistribute these binaries,unless I have purchased such a license. It is still unclear to me if the end user would also require this license too. Hopefully no. Let’s assume that. Besides,after reading carefully the Intel MKL License terms,I’m quite sure that I can redistribute the MKL-based NumPy built because it’s just runtime redistribution. So I think I will purchase an Intel Fortran Compiler license (including MKL) to be able to rebuild NumPy and SciPy in the near future but in the meantime I will just redistribute the packages built by Christoph Gohlke.
Pycharm连接windows上python
首先我们需要下载一个Python安装包,然后将安装包解压到某个盘符下,
然后我们打开Pycharm软件,点击左上角的File菜单,接着选择Settings选项,如下图所示

在弹出的Settings界面中,我们点击左侧的Project选项,如下图所示,然后点击右侧的Interpreter链接

进入到Interpreter界面中可以看到当前的解释器列表中都没有内容,我们点击右上角的设置按钮,如下图所示

接下来会弹出一个下拉菜单,我们选择第一个Add Local选项,如下图所示

然后会弹出Select Python Interpreter界面,我们定位到Python环境下的exe执行文件即可,如下图所示
回到Project Interpreter界面,我们看到本地的python环境已经被加载进来了,如下图所示

最后我们就可以新建一个Django项目了
参照文档:
http://www.coozhi.com/youxishuma/g4/61618.html
Python 3.3.2 – 如何在Windows上运行脚本
我和Python没有任何关系,只需要为一个脚本添加一个前缀到Bootstrap CSS类就可以了 。 在“how-to”作者指示以这种方式调用脚本:
$python bootstrap_namespace_prefixer.py /path/to/boostrap/dir
所以在命令行我input
$python bootstrap_namespace_prefixer.py c:bootstrap
这是给我一个错误
File "",line 1 $python bootstrap_namespace_prefixer.py c:bootstrap ^ SyntaxError: invalid Syntax
这里是github脚本的链接正如我所说我不是Python程序员,只需要这个脚本来帮助我在我的工作,但不知道我在做什么错…
如何杀死当前正在使用的端口在本地主机在Windows中?
批处理脚本删除除“开始”之外的所有文件夹
将%ComSpec%从cmd.exe更改为bash.exe
我如何用命令行或batch file来衡量吞吐量/带宽?
GIT获取多个版本库
Subst驱动器和文件夹
批文件存储行variables和总和他们
当服务已经在使用Windows批处理脚本运行时,Windows服务无法启动
IsFile,IsDirectorytestingWindows
使用variables来重命名文件
你有没有安装Python ?
安装Python ,选择你喜欢的任何版本: x64或x86 。
将Python添加到PATH :
保持胜利 ,然后按暂停 。
点击Advanced System Settings 。
点击Environment Variables 。
追加;C:python33到PATH变量。
重新启动cmd.exe或Powershell 。
尝试运行python bootstrap_namespace_prefixer.py c:bootstrap 。
python – Windows上的os.stat()
os.stat()中的哪些字段在Windows上填充了虚拟值?
python doc对此不太清楚.特别是,st_ino在Windows上产生了什么?
有人可以在Windows上运行交互式python会话并让我知道吗?我没有Windows机器所以我不能这样做.
>>> os.stat("C:\\autoexec.bat")
nt.stat_result(st_mode=33279,st_ino=0,st_dev=0,st_nlink=0,st_uid=0,st_gid=0,st_size=0,st_atime=1150614982,st_mtime=1150614982,st_ctime=1150614982)
关于Python 2.x-Windows上毫秒级的睡眠调用和python休眠毫秒的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于64位Windows上的NumPy for Python 2.7、Pycharm连接windows上python、Python 3.3.2 – 如何在Windows上运行脚本、python – Windows上的os.stat()等相关知识的信息别忘了在本站进行查找喔。
本文标签: