首页 \ 问答 \ for循环崩溃python(for-loop crashes python)

for循环崩溃python(for-loop crashes python)

我有一个用ctypes包装在Python中的C库,我在下面有这个DLL,当我要求时打印出时间值。 但不是通过每个项目并手动要求它打印出50000个值的时间。 我想我创建了一个for循环,但它无法正常工作。

这是我的代码的一个小例子:

import ctypes
from ctypes import *

MultiF = (b'path_to_file')   
dll = CDLL('path_to_dll') 

PN = ctypes.c_char_p(b'Paramter_name')
startTime = ctypes.c_double(-value)
stopTime = ctypes.c_double(value)
DT_RETURN = 0x0100
DT_FLOAT = 0x0001
convertType = (DT_RETURN|DT_FLOAT)
Null = 0


dll.readSParm.argtypes = (POINTER(SFile), c_char_p, c_double, c_double, c_double, POINTER(TTag), c_ushort,)   
dll.readSParm.restype = POINTER(SParm)

g = dll.readSParm(f, PN, startTime, stopTime, Null, None, convertType)

print(g[0].time[0])
print(g[0].time[1])
print(g[0].time[50000])

这些是代码给我的返回值:

-1031.0762939453125
-1031.0362548828125
0.0

我想最终把所有这些数字都放到一个数组中去绘制。 所以我创建了一个失败的for循环:

time = (g[0].time)
for i in time:
    print(time[1])

这只会反复打印第一个值,直到Python崩溃。 我的问题是:如何让它在循环中运行并打印出所有50000个值?

编辑

这有效:

 time = (g[0].time)
 for i in time:
    print(i)

但随后它崩溃了Python


I have a C library that i wraped in Python with ctypes and I have this DLL below that prints out the time values when i ask it to. But rather than going through each item and manually asking it to print out 50000 values for time. I think i created a for loop, but it doesn't work properly.

Here is a small example of my code:

import ctypes
from ctypes import *

MultiF = (b'path_to_file')   
dll = CDLL('path_to_dll') 

PN = ctypes.c_char_p(b'Paramter_name')
startTime = ctypes.c_double(-value)
stopTime = ctypes.c_double(value)
DT_RETURN = 0x0100
DT_FLOAT = 0x0001
convertType = (DT_RETURN|DT_FLOAT)
Null = 0


dll.readSParm.argtypes = (POINTER(SFile), c_char_p, c_double, c_double, c_double, POINTER(TTag), c_ushort,)   
dll.readSParm.restype = POINTER(SParm)

g = dll.readSParm(f, PN, startTime, stopTime, Null, None, convertType)

print(g[0].time[0])
print(g[0].time[1])
print(g[0].time[50000])

these are the return values that the code give me:

-1031.0762939453125
-1031.0362548828125
0.0

I want to eventually get all of these number into an array to be graphed. So I created a for loop that is failing:

time = (g[0].time)
for i in time:
    print(time[1])

This only prints the first value over and over and over again until Python crashes. My question in this: How can I get it to run on a loop and print out all 50000 values?

Edit

This works:

 time = (g[0].time)
 for i in time:
    print(i)

but then it crashes Python


原文:https://stackoverflow.com/questions/45064471
更新时间:2023-07-16 06:07

最满意答案

我也有这个问题 - 有时候iTunes会发狂并删除数据。 大多数应用程序对于人们抱怨都不够重要,但如果是你的,你会听到它。 看来,你做到了。

我的理论是在iTunes中出现问题并卸载删除数据的应用程序,然后重新安装它 - 新鲜和薄荷。

我可以建议的一件事是将数据存储在Keychain和Documents文件夹中,并查看这两个地方。 卸载应用程序时,钥匙串不会被清理,至少不会立即清理。 但是,当备份恢复到不同的设备时,密钥链不会被携带,因此文档仍然是必须的。

另一种选择是在用户的许可下鼓励在线备份。 当然你需要控制访问权限,这有点麻烦。


I have this problem too - sometimes iTunes goes berserk and deletes data. Most apps are not important enough for people to complain, but if yours is you will hear about it. As it seems, you do.

My theory is that something goes wrong in iTunes and it uninstalls the app deleting the data, and then reinstalls it back - fresh and minty.

One thing I can suggest is storing data in both Keychain and Documents folder, and looking in both of these places. When an app is uninstalled the keychain is NOT cleaned up, at least not right away. However when backup is restored to a different device keychain is not carried along, so Documents is still a must.

The other option is to encourage online backup with user's permission. Of course you need to control access so that's a bit of a bother.

相关问答

更多
  • 我不会去寻找存储NSUserDefaults的plist,因为它没有直接暴露给API,因此是一个可以随时更改的实现细节。 代替, [[NSUserDefaults standardUserDefaults] dictionaryRepresentation] 将为您提供一个NSDictionary其中包含您的应用已存储的所有键值对。 I wouldn't go looking for the plist that stores NSUserDefaults, because it's not direct ...
  • 一个更清洁的方法是创建一个自定义的BackupHelper : public class DbBackupHelper extends FileBackupHelper { public DbBackupHelper(Context ctx, String dbName) { super(ctx, ctx.getDatabasePath(dbName).getAbsolutePath()); } } 然后将其添加到BackupAgentHelper : public vo ...
  • 当我进行备份时,我将它创建为包含带有存储版本备份的plist文件的zip文件。 当我恢复时,我检查该版本,如果备份比当前版本更新,我拒绝恢复。 在较旧的应用程序版本中恢复备份没有任何意义。 只要你有必要的模型,它会正常工作。 When I make backup I create it as zip file containing plist file with stored version of backup in it. When I do restore I check that version an ...
  • 备份过程不会创建具有实际SQL语句的文件,它会创建一个二进制文件。 所以#1不是一个备份文件(它可能是一个保存的脚本来重新创建模式)。 我会尝试使用SQL Server Management Studio来恢复第二个文件并查看会发生什么。 我不认为它会允许你恢复一个无效的文件,但我会采取一些基本的预防措施,如先备份系统。 The backup process would not create a file with actual SQL statements, it would create a binar ...
  • 如果你只是想要自动备份,那么采用一种完整的编程语言是一种更简单的方法: http://docs.mongodb.org/manual/tutorial/backup-databases-with-filesystem-snapshots/ 如链接所示,下面的命令就足够了。 你可以把它放在一个statup-script / daemon中以常规频率执行它: 备份: lvcreate --size 100M --snapshot --name mdb-snap01 /dev/vg0/mongodb 恢复: l ...
  • 我也有这个问题 - 有时候iTunes会发狂并删除数据。 大多数应用程序对于人们抱怨都不够重要,但如果是你的,你会听到它。 看来,你做到了。 我的理论是在iTunes中出现问题并卸载删除数据的应用程序,然后重新安装它 - 新鲜和薄荷。 我可以建议的一件事是将数据存储在Keychain和Documents文件夹中,并查看这两个地方。 卸载应用程序时,钥匙串不会被清理,至少不会立即清理。 但是,当备份恢复到不同的设备时,密钥链不会被携带,因此文档仍然是必须的。 另一种选择是在用户的许可下鼓励在线备份。 当然你需 ...
  • 这不是解释根本原因的答案,遗憾的是我仍然不知道原因。 我在这里介绍的是解决方案让我能够应对它。 很简单,整个渲染过程用try / catch包围如下: try { ... // calls go within here to render to the canvas many times ... } catch (java.lang.IllegalStateException excep ...
  • 将所有备份文件解压缩到单个文件夹。 获取主数据库文件的名称。 将扩展名替换为.pat 。 使用该名称创建零长度文件,例如database.pat 。 在这个简单的步骤之后,调用JetRestoreInstance API,它将从该文件夹恢复备份。 Unpack all backed up files to a single folder. Take the name of your main database file. Replace extension to .pat. Create zero-leng ...
  • 选项#1充满了很多问题。 从来自外部源的文件中加载数据库并非易事。 我不推荐它。 选项#3应该是可能的 - 但它要求用户设置一个不需要(imho)的Google帐户。 此外,添加新日历和/或许多事件将不是许多用户喜欢的功能。 我个人也讨厌它。 第二种选择似乎最有希望。 您可以根据自己的喜好构建它。 您甚至可以只需要一个简单的识别码进行备份 - 或者只提供“实时”同步。 确实,您需要某种服务器和会计系统 - 但这些都是标准和服务器便宜的。 这个选项将是我的选择之一。 Option #1 is filled w ...
  • 我认为在您描述的场景中,在不更改(或冲突)“更新”数据的情况下恢复旧数据的问题并不是很难解决。 看起来基本上你只是想把旧数据(记录)“添加”到新数据库中,假设旧数据与新数据没有逻辑冲突(也就是说,在语义上可以创建新数据。旧数据)。 我认为,在恢复过程中处理主要关键冲突将是最重要的考虑因素。 我们来看两个案例: 1:您正在使用数据库的主键值功能的自动生成(例如,使用SQLite表的AUTOINCREMENT列)。 假设在恢复过程开始之前,“较新的”数据库记录可能使用了主键(ROWID)值1到10。 如果您的“ ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)