के साथ विफल रहता है मेरी प्रोजेक्ट में मैं पाइथन की multiprocessing
लाइब्रेरी का उपयोग कर रहा हूं ताकि __main__ में कई प्रक्रियाएं हो सकें। इस परियोजना को PyInstaller 2.1.1 का उपयोग कर एक एकल विंडोज एक्सई में पैक किया जा रहा है।पायइंस्टॉलर-निर्मित विंडोज एक्सई मल्टीप्रोसेसिंग
मैं बहुत की तरह नई प्रक्रियाओं बनाने के लिए:
from multiprocessing import Process
from Queue import Empty
def _start():
while True:
try:
command = queue.get_nowait()
# ... and some more code to actually interpret commands
except Empty:
time.sleep(0.015)
def start():
process = Process(target=_start, args=args)
process.start()
return process
और __main__ में:
if __name__ == '__main__':
freeze_support()
start()
दुर्भाग्य से, जब एक EXE में आवेदन पैकेजिंग और इसे शुरू करने, मैं WindowsError
5 या 6 मिलता है (लगता है यादृच्छिक) इस लाइन पर:
command = queue.get_nowait()
PyInstaller के मुखपृष्ठ पर एक नुस्खा का दावा है कि जब मैं एक फ़ाइल के रूप में एप्लिकेशन को पैकेजिंग करता हूं तो मुझे विंडोज़ में मल्टीप्रोसेसिंग सक्षम करने के लिए अपना कोड संशोधित करना होगा।
मैं यहाँ कोड के पुनरुत्पादन हूँ:
import multiprocessing.forking
import os
import sys
class _Popen(multiprocessing.forking.Popen):
def __init__(self, *args, **kw):
if hasattr(sys, 'frozen'):
# We have to set original _MEIPASS2 value from sys._MEIPASS
# to get --onefile mode working.
# Last character is stripped in C-loader. We have to add
# '/' or '\\' at the end.
os.putenv('_MEIPASS2', sys._MEIPASS + os.sep)
try:
super(_Popen, self).__init__(*args, **kw)
finally:
if hasattr(sys, 'frozen'):
# On some platforms (e.g. AIX) 'os.unsetenv()' is not
# available. In those cases we cannot delete the variable
# but only set it to the empty string. The bootloader
# can handle this case.
if hasattr(os, 'unsetenv'):
os.unsetenv('_MEIPASS2')
else:
os.putenv('_MEIPASS2', '')
class Process(multiprocessing.Process):
_Popen = _Popen
class SendeventProcess(Process):
def __init__(self, resultQueue):
self.resultQueue = resultQueue
multiprocessing.Process.__init__(self)
self.start()
def run(self):
print 'SendeventProcess'
self.resultQueue.put((1, 2))
print 'SendeventProcess'
if __name__ == '__main__':
# On Windows calling this function is necessary.
if sys.platform.startswith('win'):
multiprocessing.freeze_support()
print 'main'
resultQueue = multiprocessing.Queue()
SendeventProcess(resultQueue)
print 'main'
इस "समाधान" के साथ मेरा हताशा है कि, एक, यह बिल्कुल स्पष्ट नहीं वास्तव में क्या यह पैच है, और दो, कि यह एक ऐसे में लिखा है दृढ़ तरीके से यह अनुमान लगाना असंभव हो जाता है कि कौन से हिस्से समाधान हैं, और जो केवल एक उदाहरण हैं।
क्या कोई इस मुद्दे पर कुछ प्रकाश साझा कर सकता है, और अंतर्दृष्टि प्रदान करता है कि एक परियोजना में वास्तव में क्या बदलाव करने की आवश्यकता है जो PyInstaller- निर्मित एकल फ़ाइल विंडोज एक्जिक्यूटिव में मल्टीप्रोसेसिंग को सक्षम बनाता है?
नुस्खा इस मुद्दे को ठीक करता है? – dano
ठीक है, यह अस्पष्ट है (कम से कम मेरे लिए) नुस्खा कैसे लागू करें। मेरे मुख्य पायथन लिपि में उपरोक्त कोड को चिपकाकर काम नहीं करता है, या तो, क्योंकि यह मेरे पायथन स्क्रिप्ट से संबंधित दो और अपवाद उठाता है। जो मुझे बताता है कि नुस्खा मौलिक रूप से त्रुटिपूर्ण है। – nikola
यदि आप सिर्फ एक स्टैंडअलोन स्क्रिप्ट के रूप में नुस्खा चलाते हैं, तो क्या यह त्रुटियों के बिना चलता है? – dano