aspose file tools*
The moose likes Jython/Python and the fly likes Issue with global variables in jython multithreading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "Issue with global variables in jython multithreading" Watch "Issue with global variables in jython multithreading" New topic
Author

Issue with global variables in jython multithreading

ramaravi mohanan
Greenhorn

Joined: Nov 19, 2013
Posts: 1
I am importing an 3rd party library which has some global variables.

The global variables are updated when my script calls functions in the third party library.

But I want to execute multiple instances of my script as threads in parallel in such a way that the global variables should be global only the specific thread.
Each thread needs to have its own copy of global variable.


I am locked into using Jython 2.1 ,it dosent seem to have threading.local().


eg:

Script A

import wlstModule as wl #External module

wl.connect('xx','xxx,'t3://xxx:7001') #This would update global variable cmo and maybe some other variables in wlstModule


Script B needs to call multiple threads of Script A in parallel and each thread should see its own version of cmo.


Is there any way to do this.Please help.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Even without multi-threading, I learned long ago that global variables are really nasty things.

I'm not conversant with jython, but Python has the ability to operate in an object-oriented mode. I would consider that approach.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue with global variables in jython multithreading