Thanks Alok, I did experiment with both of those. Will try this again next.

On 22 Feb 2017 11:30, "Alok Gandhi" <alok.gandhi2...@gmail.com> wrote:

> And for completeness also pass  creationflags=DETACHED_PROCESS in Popen().
>
> On Wed, Feb 22, 2017 at 7:28 PM, Alok Gandhi <alok.gandhi2...@gmail.com>
> wrote:
>
>> Hi Marcus,
>>
>> I am not sure if this will surely help, but you can set `close_fds=True`
>> in subprocess.Popen(). This ensures the subprocess is spawned without
>> inheriting any handles from the parent process. Again, I am not sure if
>> this is the correct solution as I am not on windows and also do not have
>> access to maya at this moment, but I think it is worth investigating. Here
>> is a StackOverflow answer dealing with a similar problem:
>> http://stackoverflow.com/a/13593715
>>
>> -Alok
>>
>>
>> On Wed, Feb 22, 2017 at 6:38 PM, Marcus Ottosson <konstrukt...@gmail.com>
>> wrote:
>>
>>> Just to be clear, the problem is leaving this subprocess open (you'll
>>> get a new terminal window appear) when trying to close down Maya. Doing so
>>> causes Maya to hang.
>>>
>>> On 22 February 2017 at 10:08, Marcus Ottosson <konstrukt...@gmail.com>
>>> wrote:
>>>
>>>> Hi all,
>>>>
>>>> I’m struggling to understand why my Maya session deadlocks when leaving
>>>> a subprocess open whilst listening to its stdout in a thread.
>>>>
>>>> The thread is deamonised, and without the thread then closing down Maya
>>>> works well.
>>>>
>>>> I’ve narrowed down the problem into this.
>>>>
>>>> import sysimport timeimport subprocessimport threading
>>>>
>>>> child = """
>>>> import sys
>>>>
>>>> while True:
>>>>     line = sys.stdin.readline()
>>>>     sys.stdout.write("child: Input: %s" % line)
>>>>
>>>> """
>>>>
>>>> popen = subprocess.Popen(
>>>>     ["c:/python27/python.exe", "-u", "-c", child],
>>>>     stdout=subprocess.PIPE,
>>>>     stdin=subprocess.PIPE
>>>> )
>>>> def listen():
>>>>     def _listen(out):
>>>>         time.sleep(1)  # Give subprocess a second to launch
>>>>         print("parent: Listening..")
>>>>         for line in iter(out.readline, b""):
>>>>             sys.stdout.write(line)
>>>>         print("parent: Closing..")
>>>>         out.close()
>>>>
>>>>     thread = threading.Thread(target=_listen, args=[popen.stdout])
>>>>     thread.daemon = True
>>>>     thread.start()
>>>> def send(text):
>>>>     popen.stdin.write(text + "\n")
>>>>     popen.stdin.flush()
>>>>
>>>> listen()
>>>> send("hello")
>>>>
>>>> This is on Windows, I haven’t tested other OSs yet, but would expect
>>>> different results there. I suspect the issue is an open handle to
>>>> stdout, but would still have expected the thread to forcefully exit
>>>> and not make a fuzz.
>>>>
>>>> Any ideas?
>>>> ​
>>>> --
>>>> *Marcus Ottosson*
>>>> konstrukt...@gmail.com
>>>>
>>>
>>>
>>>
>>> --
>>> *Marcus Ottosson*
>>> konstrukt...@gmail.com
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Python Programming for Autodesk Maya" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to python_inside_maya+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/python_inside_maya/CAFRtmOA_eDnLSUr_v89jxS6Qa%3DUNEGc0eF
>>> %2B0ygHbqTo-E03Sgw%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOA_eDnLSUr_v89jxS6Qa%3DUNEGc0eF%2B0ygHbqTo-E03Sgw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>>
>
>
>
> --
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/python_inside_maya/CAPaTLMR37jwOsJSW9MenrX2i4KsrG
> bEtdyZBCdW1zKdWewhRng%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAPaTLMR37jwOsJSW9MenrX2i4KsrGbEtdyZBCdW1zKdWewhRng%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOChhX5pp1RLeOE_B7YyTio1end82ARgtzsTCpgUm%2B2Fyg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to