本文介绍了线程和Windows。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨! 我一定是在错误的地方搜索或者用错误的 关键字搜索但是我找不到如何实现诸如 之类的东西Windows上的线程模块所做的事情(95,98和XP是我的客户使用的 )。如果可能的话,我更喜欢 标准库中提供的东西。 我有一个简单的任务,我希望我的GUI能够打开几个 应用程序同时进行。使用线程模块一切 在Linux上完美运行,但程序不能在Windows上运行。 任何关于我应该做什么的提示? 工作代码非常简单,就是我需要的两个 平台(伪代码如下): 导入线程 (...) 类MyApplication(...): (...) def someMethod(...): (...) def temporaryFunction(): os.spawnv(''P_NOWAIT' ',''another.py'',[''another.py'',参数]) thread = threading.Thread(target = temporaryFunction) 线程。 start() def anotherMethod(...): (...) def temporaryFunction(): os.spawnv(''P_NOWAIT'',''yetanother.py'',[''yetanother.py'',参数]) thread = threading.Thread(target = temporaryFunction ) thread.start() 等等。 (是的,我可以考虑''temporaryFunction''并减少我的应用程序中的5行代码,但我仍然不知道有什么需要做什么来 使它可以在Windows上运行,所以我将其保留原样并稍后考虑它。) 有关如何以便携方式实现这一点的任何提示?或者是什么 我必须使用其他代码才能在Windows中运行? 提前致谢, - 戈多伊。 < go *** @ metalab.unc.edu> Hi!I must have been searching in the wrong places or with the wrongkeywords but I couldn''t find out how to implement something such aswhat is done by the threading module on Windows (95, 98 and XP are theones used by my clients). My preference is for something available inthe standard library if possible. I have a simple task where I want my GUI to be able to open severalapplications simultaneously. Using the threading module everythingworks perfectly on Linux but the program won''t run on Windows.Any hints on what should I do? The working code is really simple and is all what I need on bothplatforms (pseudo-code follows):import threading(...) class MyApplication(...):(...)def someMethod(...):(...)def temporaryFunction():os.spawnv(''P_NOWAIT'', ''another.py'', [''another.py'', parameters])thread = threading.Thread(target = temporaryFunction)thread.start()def anotherMethod(...):(...)def temporaryFunction():os.spawnv(''P_NOWAIT'', ''yetanother.py'', [''yetanother.py'', parameters])thread = threading.Thread(target = temporaryFunction)thread.start()and so on. (Yes, I could factor ''temporaryFunction'' and reduce 5 lines of code inmy application, but I still don''t know what will be necessary to do tomake it work on Windows, so I left it as is and factor it later.)Any hints on how to accomplish that in a portable way? Or whatadditional code will I have to use to make it work in Windows?Thanks in advance,--Godoy. <go***@metalab.unc.edu>推荐答案 http://www.python.org/doc/current/lib/os- process.html 说 .... .... .... spawnl(mode,path,...) spawnle(mode,path,...,env) spawnlp(mode,file,...) spawnlpe(mode,file,...,env) spawnv(mode,path,args) spawnve(mode,path, args,env) spawnvp(mode,file,args) spawnvpe(mode,file,args,env) .... .... .... 可用性:Unix,Windows。 spawnlp(),spawnlpe(),spawnvp()和 spawnvpe()在Windows上不可用。版本1.6新增。 .... .... .... 问候 Peter http://www.python.org/doc/current/lib/os-process.html says............spawnl(mode, path, ...)spawnle(mode, path, ..., env)spawnlp(mode, file, ...)spawnlpe(mode, file, ..., env)spawnv(mode, path, args)spawnve(mode, path, args, env)spawnvp(mode, file, args)spawnvpe(mode, file, args, env)............Availability: Unix, Windows. spawnlp(), spawnlpe(), spawnvp() andspawnvpe() are not available on Windows. New in version 1.6.............RegardsPeter 所以我应该安全,因为我正在使用spawnv(而不是spawnvp或 spawnvpe)。 :-) 无论如何,谢谢。 见到你, - Godoy。 < go *** @ metalab.unc.edu> So I should be safe since I''m using spawnv (and not spawnvp orspawnvpe). :-)Thanks anyway.See you,--Godoy. <go***@metalab.unc.edu> 这篇关于线程和Windows。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 16:31