Python multiprocessing module is not recognized -- not supported by Sikuli/Jython

Asked by george munteanu

Hello,

[Problem:]
if the python script includes multiprocessing module and it is triggered by bat file, then system will return: [error] ImportError ( No module named multiprocessing )

[Input:]
import multiprocessing
number = multiprocessing.cpu_count()
print("Creating " + str(number) + " threads")
note: This is just a dummy example. The same code works when run from Python IDLE

[Output:]
 [error] ImportError ( No module named multiprocessing )

Therefore, when you get the chance, please tell me what I have done wrong.

Take care

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
george munteanu
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

In Sikuli scripts we use the Python LANGUAGE, but not the Python eco-system (usually called C-Python).

Sikuli is Java based and we therefor use the Jython interpreter.

With Jython you only can use Python modules completely written in Python or the equivalent modules ported to Java, so they can be used with Jython. If a Python module is C-based (usually written in C++) or depends on C-based stuff (like the Win32.dll) it cannot be used with Jython and hence not with Sikuli.

Revision history for this message
george munteanu (georgetemenos) said :
#2

thanks RaiMan for the quick response.
I found a workaround for this situation.
framework: bat file > py > bat file > py

(1)
- create .bat file
[code] : start /i /b /wait C:\Sikuli\sikuli\sikuli\runIDE.cmd -r "C:\<sikuli_test>"
(2)
- this bat file will trigger the .py inside sikuli folder (e.g sikuli_test.py)
[code]: start C:\python27\python.exe C:\<first.py>
(3)
- this first .py will trigger another .bat file
[code]: def checkPaymentStatus():
   import subprocess
   filepath=r"C:\run.bat"
   subprocess.call(filepath, shell=True)
# Call checkPaymentStatus
checkPaymentStatus()
(4)
- the 2nd .bat file will trigger another .py that will execute the final code
[final_code]:
import multiprocessing
number = multiprocessing.cpu_count()
f = open ('test.txt', 'w')
f.write(str(number))
f.close()

I hope this help others.

Take care