New to threading. Right idea???

David Ascher da at ski.org
Mon Jun 14 01:25:26 EDT 1999


On Sun, 13 Jun 1999, Karl Putland wrote:

> I need some advise.  Am I on the right track?

Not quite.  As you say, threads are independent paths of execution.  The
key word there is "path of execution" =).  In other words, everything but
the path of execution is shared, especially globals, and in Python, the
state of the interpreter.  The two threads share the same list of imported
modules, etc.

What you're thinking of is processes, not threads.  On unix, that's done
with a fork().  There is no simple equivalent on Windows, alas.  Not that
it would help (see below).

> One of the functions in the dll is EXPENSIVE.  It's not mine and I doubt
> they will rework it so I have to live with it.  the EXPENSIVE function must
> be called at the begining and ties all activity in the dll to a specific
> directory.  If you want to change directories you must call unexpensive then
> EXPENSIVE again with the new directory as an argument.  If the dll is loaded
> and EXPENSIVE has been called sucessive calls to EXPENSIVE return FALSE.

If you must call EXPENSIVE for each directory, then you must -- I don't
think there's any way around that.  Loading the same DLL multiple times
won't help if you have to call EXPENSIVE for each (especially if
unexpensive is, well, unexpensive =).  If EXPENSIVE is VERY_EXPENSIVE,
where VERY_EXPENSIVE >> cost of loading the DLL, then even a fork()
wouldn't help much, even if it were available on your OS.

--david ascher






More information about the Python-list mailing list