线程和Windows。 [英] Threading and Windows.

查看:43
本文介绍了线程和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 wrong
keywords but I couldn''t find out how to implement something such as
what is done by the threading module on Windows (95, 98 and XP are the
ones used by my clients). My preference is for something available in
the standard library if possible.

I have a simple task where I want my GUI to be able to open several
applications simultaneously. Using the threading module everything
works 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 both
platforms (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 in
my application, but I still don''t know what will be necessary to do to
make 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 what
additional code will I have to use to make it work in Windows?
Thanks in advance,
--
Godoy. <go***@metalab.unc.edu>

推荐答案

Jorge Godoy于2003年9月29日星期一将这条鱼喂给企鹅

05:00 am:
Jorge Godoy fed this fish to the penguins on Monday 29 September 2003
05:00 am:

我有一个简单的任务,我希望我的GUI能够同时打开几个
应用程序。使用线程模块一切都可以在Linux上完美运行,但程序不能在Windows上运行。

请原谅我,如果这有一些明显的方面我错过了 - 我在os.spawnv *系列中没有经验



但是,我对os.spawnv()的文档表明这个
单独
调用将创建一个单独的/新进程。并且你用无等待的参数称它为
...那你为什么甚至需要线程

开销呢?

def temporaryFunction ():
os.spawnv(''P_NOWAIT'',''another.py'',[''another.py'',
参数])


嗯,如果是another.py是目标,你可能会遇到Windows不知道如何从

命令行启动.py文件的可能性。 Windows(尤其是W9x系列)对我的

知识,荣誉#!脚本文件中的行。


- =============================== =================== ============<
wl ***** @ ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG<
wu******@dm.net | Bestiaria支持人员<
========================================= ========= ============<
Bestiaria主页: http://www.beastie.dm.net/ <
主页: http://www.dm.net/~wulfraed/ <

I have a simple task where I want my GUI to be able to open several
applications simultaneously. Using the threading module everything
works perfectly on Linux but the program won''t run on Windows.
Forgive me if this has some obvious facet that I''m missing -- I''m not
experienced in os.spawnv* family.

However, the documentation I have for os.spawnv() suggests that this
call alone will create a separate/new process. And you are calling it
with a no-wait argument... So why do you even need the threading
overhead?
def temporaryFunction():
os.spawnv(''P_NOWAIT'', ''another.py'', [''another.py'',
parameters])
Hmmm, if "another.py" is the target, you may be encountering the
possibility that Windows doesn''t know how to start a .py file from the
command line. Windows (especially the W9x line) doesn''t, to my
knowledge, honor #! lines in script files.

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <






Jorge Godoy< go *** @ metalab.unc.edu>在消息新闻中写道:< m3 ************ @ ieee.org> ...
Jorge Godoy <go***@metalab.unc.edu> wrote in message news:<m3************@ieee.org>...
嗨!

我一定是在错误的地方搜索或使用错误的关键字搜索,但我无法找到如何实现诸如
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)
thread.start()

def anotherMethod(...):
(...)
def temporaryFunction():
os.spawnv('''P_NOWAIT '',''yetanother.py'',[''yetanother.py'',参数])
thread = threading.Thread(target = temporaryFunction)
thread.start()

A等等。

(是的,我可以考虑''temporaryFunction''并减少我的应用程序中的5行代码,但我仍然不知道将需要什么要使它在Windows上运行,所以我将它保留原样并稍后考虑它。)

关于如何以便携方式实现这一点的任何提示?或者我需要使用哪些附加代码才能使其在Windows中运行?

提前感谢,
Hi!
I must have been searching in the wrong places or with the wrong
keywords but I couldn''t find out how to implement something such as
what is done by the threading module on Windows (95, 98 and XP are the
ones used by my clients). My preference is for something available in
the standard library if possible.

I have a simple task where I want my GUI to be able to open several
applications simultaneously. Using the threading module everything
works 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 both
platforms (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 in
my application, but I still don''t know what will be necessary to do to
make 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 what
additional code will I have to use to make it work in Windows?
Thanks in advance,



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() and
spawnvpe() are not available on Windows. New in version 1.6.
....
....
....
Regards
Peter


Pe **** ***@gmx.net (Peter Abel)写道:
Pe*******@gmx.net (Peter Abel) writes:
http://www.python.org/doc/current/lib/os-process.html
...
......
...
spawnl(模式,路径,......)
spawnle(模式,路径,......,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中的新功能。
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() and
spawnvpe() are not available on Windows. New in version 1.6.




所以我应该安全,因为我正在使用spawnv(而不是spawnvp或

spawnvpe)。 :-)

无论如何,谢谢。

见到你,

-

Godoy。 < go *** @ metalab.unc.edu>



So I should be safe since I''m using spawnv (and not spawnvp or
spawnvpe). :-)
Thanks anyway.
See you,
--
Godoy. <go***@metalab.unc.edu>


这篇关于线程和Windows。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆