使用多个线程执行单个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
最满意答案
问题是没有调用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.
相关问答
更多-
您可以使用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; import ...
-
您在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。 您没有提供任何相关证据,也无法从您发布的代码中分辨出来。 getOutputStream()返回一个没有来自WebService的消息的OutputStream。 这毫无意义。 OutputStreams不包含来自对等体的消息。 它们用于向对等方发送消息。 这句话和你的头衔完全没有意义。 无论如何都要检查WebService是否已成功调用? 是。 阅读响应并返回,而不是硬连线"OK" 。 而你刚刚发布的代码就是这样做的。 同意它不是最漂亮的代码。 它甚至不是正确的代码。 ...
-
如果您考虑使用纯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) { ...
-
谢谢你的所有响应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 I'll ...
-
如果要为特定服务设置超时,一旦创建了代理,就需要将其转换为BindingProvider(您已知道),获取请求上下文并设置属性。 在线JAX-WS文档是错误的,这些是正确的属性名称 MyInterface myInterface = new MyInterfaceService().getMyInterfaceSOAP(); Map
requestContext = ((BindingProvider)myInterface).getRequestContext(); req ... -
使用POST方法的webservice响应“不支持的媒体类型”(webservice response “Unsupported Media Type” with POST method)[2022-03-20]
尝试更改客户端,如下所示: 将数据:{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 suggestio ... -
我发现了问题。 我们的Test-和Prod-Environment之前有一个内部负载均衡,可自动将通信从http切换到https。 BizTalk中的WebService的WCF-CustomIsolated Receivelocation具有BasicHttpSecurityElement的basicHttpBinding选项为none。 这导致了Http 404找不到错误。 在将其设置为“transport”之后,它能够在loadbalancer中处理https重写并且它能够正常工作。 404未找到=传 ...
-
异步调用webservice(Call webservice asynchronously)[2023-09-16]
public async static Task validateLogin(JsonParameters _param, ref ValidateCredentials result, ref string excep_error) { await Task.Run(()=> { var _mobileService = new MobileService(); _mobileService.Url = ... -
不要使用自定义对象重新发明轮子。 看看这篇MSDN文章 。 最简单的事情就是抛出异常(听起来像ArgumentException在你的情况下是合适的),客户端将收到一个SoapException 。 或者,如果您想要更多控制(例如设置故障代码的能力),请SoapException抛出SoapException 。 Don't reinvent the wheel with custom objects. Look at this MSDN article. The easiest thing is just ...