473,661 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threading and 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 temporaryFuncti on():
os.spawnv('P_NO WAIT', 'another.py', ['another.py', parameters])
thread = threading.Threa d(target = temporaryFuncti on)
thread.start()
def anotherMethod(. ..):
(...)
def temporaryFuncti on():
os.spawnv('P_NO WAIT', 'yetanother.py' , ['yetanother.py' , parameters])
thread = threading.Threa d(target = temporaryFuncti on)
thread.start()
and so on.

(Yes, I could factor 'temporaryFunct ion' 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>
Jul 18 '05 #1
22 6578
Jorge Godoy fed this fish to the penguins on Monday 29 September 2003
05:00 am:

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 temporaryFuncti on():
os.spawnv('P_NO WAIT', '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.netc om.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/ <


Jul 18 '05 #2
Jorge Godoy <go***@metalab. unc.edu> wrote in message news:<m3******* *****@ieee.org> ...
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 temporaryFuncti on():
os.spawnv('P_NO WAIT', 'another.py', ['another.py', parameters])
thread = threading.Threa d(target = temporaryFuncti on)
thread.start()
def anotherMethod(. ..):
(...)
def temporaryFuncti on():
os.spawnv('P_NO WAIT', 'yetanother.py' , ['yetanother.py' , parameters])
thread = threading.Threa d(target = temporaryFuncti on)
thread.start()
and so on.

(Yes, I could factor 'temporaryFunct ion' 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 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
Jul 18 '05 #3
Pe*******@gmx.n et (Peter Abel) writes:
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.


So I should be safe since I'm using spawnv (and not spawnvp or
spawnvpe). :-)
Thanks anyway.
See you,
--
Godoy. <go***@metalab. unc.edu>
Jul 18 '05 #4
Dennis Lee Bieber <wl*****@ix.net com.com> writes:
Forgive me if this has some obvious facet that I'm missing -- I'm not
experienced in os.spawnv* family.
Neither am I. In fact, this program was my first use of it.
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?
This isn't the behaviour I found here on a Linux box. The caller
process got 'stuck' and only worked again when the called proccess
ended.

With threads I got it working all the time.
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.


Using the thread module I could get it to work on Windows and then,
yes. I got this problem. :-)

Sorry for my lameness on Windows but this isn't my platform of
choice. I'll add some conditional and check the platform...

On the other hand, isn't there a way to associate programs with
extensions on Windows? Wouldn't this solve the problem with the call I
made? Or it only works in certain circunstances and (by Murphy's law)
this is not one of those circunstances?
Thanks for your help,
--
Godoy. <go***@metalab. unc.edu>
Jul 18 '05 #5
On Mon, 29 Sep 2003 23:29:18 -0300, Jorge Godoy <go***@metalab. unc.edu>
wrote:
Availability: Unix, Windows. spawnlp(), spawnlpe(), spawnvp() and
spawnvpe() are not available on Windows. New in version 1.6.


So I should be safe since I'm using spawnv (and not spawnvp or
spawnvpe). :-)


For running a file based on its extension, you could try os.startfile().

J.
Jul 18 '05 #6
Jorge Godoy fed this fish to the penguins on Monday 29 September 2003
07:31 pm:

This isn't the behaviour I found here on a Linux box. The caller
process got 'stuck' and only worked again when the called proccess
ended.
Strange...

On the other hand, isn't there a way to associate programs with
extensions on Windows? Wouldn't this solve the problem with the call I
made? Or it only works in certain circunstances and (by Murphy's law)
this is not one of those circunstances?


I think NT has the ability to go by extension, but not W9x.

You might have to explicitly invoke the python executable, and pass
/it/ the .py file as the first argument

-- =============== =============== =============== =============== == <
wl*****@ix.netc om.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/ <


Jul 18 '05 #7
Jordan Krushen <jo****@krushen .com> writes:
For running a file based on its extension, you could try os.startfile().


Thank you.

It will probably solve my problem on Windows.

Unfortunately, it isn't a portable way since this command doesn't even
exist on my Linux (Python 2.2.2). I will have to use the conditional I
said on my previous message.
Thanks again,
--
Godoy. <go***@metalab. unc.edu>
Jul 18 '05 #8
Dennis Lee Bieber <wl*****@ix.net com.com> writes:
Jorge Godoy fed this fish to the penguins on Monday 29 September 2003
07:31 pm:

This isn't the behaviour I found here on a Linux box. The caller
process got 'stuck' and only worked again when the called proccess
ended.
Strange...


I thought the same thing and even thought I was using os.spawnv() in a
wrong way. Even with the 'P_NOWAIT' flag it still hangs.

I'm using:

Python 2.2.2 (#1, Mar 6 2003, 13:36:19)
[GCC 3.2.2] on linux-i386
I haven't investigated os.spawnv() alone in Windows to see if this
also happens there. It will be funny if by this very first time the
problem is on the Linux box instead of the Windows box (since I'm more
used to unices, I'm more familiar with their quirks than with
Windows', specially with all those 'flavours' of Windows...).
I think NT has the ability to go by extension, but not W9x.
Windows XP can't go by extension either.
You might have to explicitly invoke the python executable, and pass
/it/ the .py file as the first argument


I see. If it doesn't work using os.startfile() as suggested on another
message I'll probably stick with this approach.
Thanks!

--
Godoy. <go***@metalab. unc.edu>
Jul 18 '05 #9
Hello Jorge,
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. What do you mean by "won't run"? Does it crash? ...
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):
[...]

Just guessing:
1. The spawnl of a .py don't work. You need to start the python interpreter
on the .py file
2. The GUI toolkit you're using is causing the problem. To check this try
lauch threads without any gui and see if it works.

HTH.
Miki
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
555
by: CK | last post by:
I have the following code in a windows service, when I start the windows service process1 and process2 work fine , but final process (3) doesnt get called. i stop and restart the windows service and the final process(3) gets called. what am I doing wrong with the threading? by the way Directory.GetFiles(IncomingXMLPath1).Length is some global outcome from process 1. Thanks 1)
13
371
by: RCS | last post by:
I have a UI that needs a couple of threads to do some significant processing on a couple of different forms - and while it's at it, update the UI (set textboxes, fill in listviews). I created a base class for the worker class, and made up some functions/delegates to handle the invoke stuff for the UI and that was fine for a prototype. I rewrote this chunk, broke things out into different classes - but the threading is still the same - and...
7
4059
by: Terry Olsen | last post by:
I run this code: Private Sub p_recv(ByVal sender As Object, ByVal e As SerialReceivedEventArgs) Handles p.ReceivedEvent txtRecv.Text += p.ReadExisting End Sub I get this error: --------------------ERROR TEXT-------------------- Illegal cross-thread operation: Control 'txtRecv' accessed from a thread
0
1982
by: Colmeister | last post by:
I recently read Jason Clark's excellent article on Unhandled Exceptions (http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx) and have attempted to incorporate the features he talks about in a new application I'm writing. However, when I try to use ThreadStart to do some work in a separate thread from my GUI, the methods Jason described don't seem to catch the exception. Take the following source code: Public Class...
6
1892
by: hzgt9b | last post by:
Using VS 2003, .NET: I developed a windows application that performs several actions based on an input file. The application displays a progress bar as each action executes. Based on new requirements, this application needs to be able to shell off other processes and wait while in the mean time displaying a progress bar of the process's. I am using the System.Disgnostics.Process class to "start" and "waitForExit" of these processes... I...
17
6408
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. Note, the Windows task manager shows 2 CPUs on the Performance tab with hyper-threading is turned on. Both Python 2.3.5 and 2.4.3 (downloaded from python.org) have this problem. The operating system is MS Windows XP Professional.
0
1586
by: kingcrowbar.list | last post by:
Hello Everyone I have been playing a little with pyGTK and threading to come up with simple alert dialog which plays a sound in the background. The need for threading came when in the first version i made, the gui would freeze after clicking the close button until pygame finished playing the sound. In Windows it was acceptable because it could be ignored easily, but in
7
2367
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has finished. I am trying to follow this example : http://www.codeproject.com/cs/miscctrl/progressdialog.asp But although the messages still get moved, the progress window never does anything. Here is my code in full, if anybody who knows...
19
1794
by: frankiespark | last post by:
Hello all, I was perusing the internet for information on threading when I came across this group. Since there seems to be a lot of good ideas and useful info I thought I'd pose a question. Threading is a new concept for me to implement. Here is my problem. I have a system that receives xml files and records their file locations in a database. I can potentially receive thousands,
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
7364
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.