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

使用多个线程执行单个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.

相关问答

更多
  • 您可以使用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 ...
  • 尝试更改客户端,如下所示: 将数据:{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未找到=传 ...
  • 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 ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)