0
votes

I need to create a threading functionality in my .net project using Python. For this I have created a console application (C#) and added Python and IronPython references.When I run the multithreading code I am getting following error

IronPython.Runtime.Exceptions.ImportException: 'No module named threading'

Is there any references need to add for Threading? When I googled it i didn't find any reference to add.

Following is the code

import threading
from threading import Thread

def PaymentCalculation(userid):
    sum = 1+1
    return sum

def ProcessingData():    
    data = GetAssigneeData() #will return dataset from DB 

    for member in data.Tables[0].Rows:
        pthread = Thread(target=PaymentCalculation, args=(member["UserId"],)) 
        pthread.start()

I solved the issue. I was used normal python code. Its is not IronPython code. I made change code like below.

from System.Threading import (
ApartmentState,
Thread, ThreadStart,ParameterizedThreadStart
)
def PaymentCalculation(userid):
    sum = 1+1
    return sum
def ProcessingData():
    data = GetAssigneeData()
    for member in data.Tables[0].Rows:
        thread = Thread(ParameterizedThreadStart(PaymentCalculation)) 
        thread.SetApartmentState(ApartmentState.STA) 
        thread.Start(member["UserId"])
1
can you check sys path? import sys, print sys.path. check those paths for threading module. - Ali Yılmaz
its showing like this ['.' , '...\\bin\\Debug\\Lib' , '...\\bin\\Debug\\DLLs'] . what I need to check "Threading" named file. - Sajith A.K.

1 Answers

0
votes

Your sys.path do not seem to include the location for built-in python modules.

Locate python modules in your system. Let's say you found them under C:/some/dir

Try appending sys.path that directory before importing threading.

import sys
sys.path.append('C:/some/dir')
from threading import Thread
<rest of your code>