首页 \ 问答 \ 我这样做了吗?(Am I doing this right?)

我这样做了吗?(Am I doing this right?)

我有RPG游戏。 人们可以在那里买一些东西。 我为这样的项目创建了一个函数:

function item($id) {
    switch ($id) {
         case 1:
               $name  = 'item name 1';
               $price = 1200;
               break;
     }
}

我做得对吗,你怎么看,它是检索项目信息的最佳方式吗?


I have RPG game. People can buy some items there. I have created a function for items like that:

function item($id) {
    switch ($id) {
         case 1:
               $name  = 'item name 1';
               $price = 1200;
               break;
     }
}

Am I doing it right, what do you think, is it a best way to retrieve information about item?


原文:https://stackoverflow.com/questions/3637060
更新时间:2022-07-15 20:07

最满意答案

Fabric有自己的并行执行任务的工具 - 您应该使用它们,而不是仅仅尝试在多处理池中执行Fabric任务。 问题是env对象在执行任务时发生了变异,因此不同的工作者互相踩踏(除非你把锁定放进去)。


Fabric has its own facilities for parallel execution of tasks - you should use those, rather than just trying to execute Fabric tasks in multiprocessing pools. The problem is that the env object is mutated when executing the tasks, so the different workers are stepping on each other (unless you put locking in).

相关问答

更多
  • 我想我明白了为什么这个错误正在发生,以及为什么你的repro是Python 3特有的。 代码对象按值进行等式比较 ,而不是按指针,足够奇怪: static PyObject * code_richcompare(PyObject *self, PyObject *other, int op) { ... co = (PyCodeObject *)self; cp = (PyCodeObject *)other; eq = PyObject_RichCompareBool( ...
  • multiprocessing.Manager()启动一个负责处理共享列表代理的子进程。 运行时netstat输出: unix 2 [ACC] STREAM LISTENING 3921657 8457 / python / tmp / pymp-B9dcij / listener-X423Ml 这个由multiprocessing.Manager()创建的子进程会捕获您的SIGINT并退出,导致与其相关的任何事情被解除引用,因此您的“没有这样的文件”错误(根据我何时决定发送SIGINT,我还有其他几个错误 ...
  • 尝试将'%p'更改为'%P'。 是否支持'%P'取决于平台C库提供的'strftime'功能。 Try changing '%p' to '%P'. Whether '%P' is supported depends on the 'strftime' function provided by the platform C library.
  • Fabric有自己的并行执行任务的工具 - 您应该使用它们,而不是仅仅尝试在多处理池中执行Fabric任务。 问题是env对象在执行任务时发生了变异,因此不同的工作者互相踩踏(除非你把锁定放进去)。 Fabric has its own facilities for parallel execution of tasks - you should use those, rather than just trying to execute Fabric tasks in multiprocessing poo ...
  • 如果你仔细查看你发布的链接...到我的答案( https://stackoverflow.com/a/21345273/2379433 ),你会发现你确实可以做你想做的事情......即使你使用lambdas和默认dicts和各种其他python结构。 您所要做的就是用pathos.multiprocessing替换multiprocessing ......它可以工作。 请注意,我甚至在翻译工作。 >>> import numpy as np >>> from functools import parti ...
  • 相同的代码在这里工作: http://ideone.com/9kcQru : http://ideone.com/9kcQru from multiprocessing import Process def f(name): print('hello', name) if __name__ == '__main__': p = Process(target=f, args=('bob',)) p.start() p.join() 输出:你好鲍勃 你的环境有问题 Same ...
  • 这意味着,如果某些进程在其他人之前清除了队列,则他们不会获得要执行的新任务。 它是否正确? 不是的multiprocess.Pool()的主要目的是将传递的工作负载传播到其工作池 - 这就是为什么它带有所有这些映射选项 - 它的各种方法之间的唯一区别在于工作负载如何实际分布以及如何收集产生的回报。 在你的情况下,你用[(s, t0, tf, folder) for s in signals]生成的可迭代[(s, t0, tf, folder) for s in signals]将会把它的每个元素(最终取决于 ...
  • 创建新的子进程时,子进程可能 (主要取决于您使用的操作系统)重新导入当前模块。 在您的情况下,重新导入模块也会执行以下两行: Process(target=sample).start() Process(target=sample).start() 会发生什么,错误消息告诉你: 在当前进程完成其自举阶段之前,已尝试启动新进程。 这可能意味着您没有使用fork来启动子进程而您忘记在主模块中使用正确的习惯用法 在为第一个子进程设置适当的环境时,代码会尝试分叉另一个子进程。 经理检测到这一点并告诉你这不行。 i ...
  • defaultdict的行为很容易使用标准dict进行复制。 在这种情况下,我认为你可以在test简单地替换这一行: if T[s - c * x, i]: 用这一行: if T.get((s - c * x, i), False): 在开始自定义Manager对象之前,看看是否可以使用标准字典使用此代码。 但实际上似乎i每个值都将存储可以由处理i + 1的循环访问的值。 这意味着每个循环的结果取决于前一个循环,因此异步方法可能会产生错误。 要扩展此功能,请尝试以下代码: from multiproce ...
  • Windows和Linux之间的区别在于子进程的启动方式。 在Linux上,使用fork()启动子进程:新进程以与父进程相同的状态启动:python代码已经被解释,它获得了父进程内存的副本。 在Windows上它完全不同:进程spawn :启动一个新的python解释器,它再次解析python文件并执行它。 这就是为什么你的顶部print过程再次执行的原因。 有关详细信息,请参阅有关fork与spawn的文档 。 一个常见的缺陷是避免底部的if __name__ == '__main__' 。 但是,由于您 ...

相关文章

更多

最新问答

更多
  • 您如何使用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)