使用多个线程执行单个for循环(Using multiple threads to execute a single for loop)

我可以使用多个线程在python中执行单个for循环吗? 我的意思是,我的循环有大量的迭代,所以我想同时运行多个线程,每个线程可以执行一定数量的循环迭代。

假设迭代次数在很高的数量级。 例如10 ** 9。

而且,如果这是可能的,它是否会减少完成for循环执行所需的时间....?


Can I use multiple threads to execute a single for loop in python? I mean, my loop has huge number of iterations and so I would like to run multiple threads simultaneously in such a way that each thread can execute a certain number of iteration of the loop.

Assume that the number of iterations is in high orders of magnitude. 10**9 for example.

And also, if this is possible, does it reduce the time it requires to complete the execution of the for loop....?


原文:https://stackoverflow.com/questions/30964415
2022-05-13 13:05

满意答案

问题是没有调用webService。

您没有提供任何相关证据,也无法从您发布的代码中分辨出来。

getOutputStream()返回一个没有来自WebService的消息的OutputStream。

这毫无意义。 OutputStreams不包含来自对等体的消息。 它们用于向对等方发送消息。 这句话和你的头衔完全没有意义。

无论如何都要检查WebService是否已成功调用?

是。 阅读响应并返回而不是硬连线"OK"

而你刚刚发布的代码就是这样做的。

同意它不是最漂亮的代码。

它甚至不是正确的代码。 HTTP标头无效,它不会尝试读取响应。 这只是无能。 使用您发布的HttpURLConnection代码。


The problem is that the webService is not called.

You haven't provided any evidence to that effect, and it is impossible to tell from the code you've posted.

The getOutputStream() retuns an OutputStream that has no message from the WebService.

This is meaningless. OutputStreams don't contain messages from the peer. They are used to send messages to the peer. This statement and your title are completely nonsensical.

Is there anyway to check that the WebService has been called successfully?

Yes. Read the response, and return it, instead of hardwiring "OK".

And you've just posted code that does exactly that.

Agreed it is not the most beautiful code.

It isn't even correct code. The HTTP headers are invalid, and it makes no attempt to read a response. It's just incompetent. Use the HttpURLConnection code you posted.

相关问答

更多

具有XML内容的CXF Webservice响应(CXF Webservice response with XML content)

您可以使用jaxws Provider的Payload模式。 请参阅http://cxf.apache.org/docs/provider-services.html 然后,您的服务只能返回一个只是通用XML对象的Source对象。 如下所示: import javax.xml.transform.Source; import javax.xml.ws.Provider; import javax.xml.ws.Service; import javax.xml.ws.ServiceMode; i...

Webservice发送其WSDL定义作为其响应(Webservice sending its WSDL definition as its response)

您在URL中指定以获取WSDL(参数?WSDL)。 您需要为要调用的服务操作指定正确的URL。 You specified in the URL to get the WSDL (Parameter ?WSDL). You need to specify the proper URL for the service operation you want to call.

从WebService检索响应消息(Retrieving response message from WebService)

问题是没有调用webService。 您没有提供任何相关证据,也无法从您发布的代码中分辨出来。 getOutputStream()返回一个没有来自WebService的消息的OutputStream。 这毫无意义。 OutputStreams不包含来自对等体的消息。 它们用于向对等方发送消息。 这句话和你的头衔完全没有意义。 无论如何都要检查WebService是否已成功调用? 是。 阅读响应并返回,而不是硬连线"OK" 。 而你刚刚发布的代码就是这样做的。 同意它不是最漂亮的代码。 它甚至不是正...

从javascript调用webservice并等待响应(calling webservice from javascript and wait for response)

如果您考虑使用纯JavaScript(这些天很不寻常),请考虑此代码 var strURL = "localhost/services/foobar.svc"; var xmlHttpReq = false; var self = this; // Mozilla/Safari if (window.XMLHttpRequest) { self.xmlHttpReq = new XMLHttpRequest(); } // IE else if (window.ActiveXObject)...

优化Web服务响应消息(Optimizing webservice response message)

谢谢你的所有响应xD我认为我必须以自定义格式发送序列化对象,但Axis2只处理xml内容(Jax-WS)。 所以我会尝试另一个像泽西岛这样处理自定义格式(Jax-RS)的Rest服务器。 你觉得怎么样? Thank you for all your reponses xD I think that I have to send serialized objects in a custom format but Axis2 only deals with xml stuff (Jax-WS). So...

如果在指定时间内没有响应,则丢弃Webservice调用(Discard Webservice call if no response in specified time)

如果要为特定服务设置超时,一旦创建了代理,就需要将其转换为BindingProvider(您已知道),获取请求上下文并设置属性。 在线JAX-WS文档是错误的,这些是正确的属性名称 MyInterface myInterface = new MyInterfaceService().getMyInterfaceSOAP(); Map<String, Object> requestContext = ((BindingProvider)myInterface).getRequestContext()...

使用POST方法的webservice响应“不支持的媒体类型”(webservice response “Unsupported Media Type” with POST method)

尝试更改客户端,如下所示: 将数据:{track:JSON.stringify(newTrack)}更改为数据:JSON.stringify(newTrack) 为了更好的建议,请在网络选项卡上向我们发送网络捕获。 希望这有帮助 Try to change client side as below: Change data : { track : JSON.stringify(newTrack)} to data : JSON.stringify(newTrack) For better sugg...

IIS Webservice,怪异的404 http响应代码(IIS Webservice, weird 404 http response code)

我发现了问题。 我们的Test-和Prod-Environment之前有一个内部负载均衡,可自动将通信从http切换到https。 BizTalk中的WebService的WCF-CustomIsolated Receivelocation具有BasicHttpSecurityElement的basicHttpBinding选项为none。 这导致了Http 404找不到错误。 在将其设置为“transport”之后,它能够在loadbalancer中处理https重写并且它能够正常工作。 404...

异步调用webservice(Call webservice asynchronously)

public async static Task validateLogin(JsonParameters _param, ref ValidateCredentials result, ref string excep_error) { await Task.Run(()=> { var _mobileService = new MobileService(); _mobileService....

如何从webservice返回响应(How to return response from webservice)

不要使用自定义对象重新发明轮子。 看看这篇MSDN文章 。 最简单的事情就是抛出异常(听起来像ArgumentException在你的情况下是合适的),客户端将收到一个SoapException 。 或者,如果您想要更多控制(例如设置故障代码的能力),请SoapException抛出SoapException 。 Don't reinvent the wheel with custom objects. Look at this MSDN article. The easiest thing is...

相关文章

更多

Storm-源码分析-Topology Submit-Executor-mk-threads

对于executor thread是整个storm最为核心的代码, 因为在这个thread里面真正完成 ...

[转]So You Want To Be A Producer

pro-du-cer n. 1. Someone from a game publisher who ...

Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing

http://spark-project.org/ 项目首页 http://shark.cs.berk ...

Stack Overflow Architecture Update - Now At 95 Million Page Views A Month

A lot has happened since my first article on theSta ...

Solr: a custom Search RequestHandler

As you know, I've been playing with Solr lately, tr ...

A Great List of Windows Tools

Windowsis an extremely effective and a an efficient ...

Spring Data: a new perspective of data operations

Spring Data: a new perspective of data operations ...

Create a Bootable MicroSD Card

http://gumstix.org/create-a-bootable-microsd-card.h ...

Drupal Forums instead of phpBB or vBulletin: A casestudy

5th Jan, 10 Drupal drupal advanced forum drupa ...

Hadoop 1.2.1 单节点安装(Single Node Setup)步骤

为了使您快速体验Hadoop,可以在一台机子上安装单节点(Node)的hadoop。 相关阅读:单节点 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本