[Maya-Python] pass Python Vector pointer ?

2017-02-22 Thread justin hidair
how do I pass a vector pointer to MItMeshPolygon.getNormal in Python 1.0 ?

MScriptUtil doesn't have support for vector amirite? Tried with a list, 
tried initialized to None...

Also would like to know how many of you are using Python API 2.o ?

-- 
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/0049249e-a29c-4596-a92e-7d8b6ef71719%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] Re: xform rotate object space

2017-02-22 Thread justin hidair
It's best to always test on several objects, one scaled, one rotated, one 
transformations frozen, ect.. and you'll find the thing eventually... May I 
ask why you would do all that ?

-- 
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/c28b2fb6-526e-4e3d-91c1-f8b42a721a6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] Re: How to us Custom MPxData from cpp in python.

2017-02-22 Thread Cameron Fulton
Ok, so after asking I plugged away and figured out how to do it. Here is 
what I found for anyone else who is interested in doing this.

def getAttrPlug(nodeName, attrName):
selectionList = OpenMaya.MSelectionList()
try:
selectionList.add(nodeName)
except:
return None
dependNode = selectionList.getDependNode(0)
dagNode = OpenMaya.MFnDagNode(selectionList.getDagPath(0))
attrNode = dagNode.attribute(attrName)
return OpenMaya.MPlug(dependNode,attrNode)


def createPluginData(typeId, dataList):
pluginDataCreator = OpenMaya.MFnPluginData()
bdtID = OpenMaya.MTypeId(typeId)
pluginDataCreator.create(bdtID)
values = bytearray(dataList)
pluginDataCreator.data().readBinary(values, len(dataList))
return pluginDataCreator.data()

blindNode = getAttrPlug("blind", "blindData")
blindData = createPluginData(0x1948, [84,111,111,32,69,97,115,121])
dataHandle = blindNode.asMDataHandle()
dataHandle.setMPxData(blindData)



On Wednesday, February 22, 2017 at 2:16:03 PM UTC-8, Cameron Fulton wrote:
>
> Hi all,
>
> So I have a custom data type that I create in cpp that I use for an 
> attribute on a custom node. My custom data type is pretty straight forward:
> class BlindData : public MPxData
> {
>
>
>  public:
> BlindData();
> virtual ~BlindData();
>
>
>   /**
>* Copy the local data from a similar data object
>*
>* @param MPxData
>*   Data object to copy from.
>*/
>   virtual void copy(const MPxData&);
>
>
>   MStatus
>   readBinary(istream& in, unsigned int length);
>
>
>   MStatus
>   writeBinary(ostream& out);
>
>
>   MTypeId typeId() const;
>
>
>   MString name() const;
>
>   static MString typeName;
>   static MTypeId id;
>   static void* creator();
>
>
>   std::vector m_data;
> };
>
> And then I just use that as a type for my attr on my node
>   MFnTypedAttribute tAttr;
>   MStatus stat;
>
> blindDataAttr = tAttr.create("blindData",
>  "blind",
>  BlindData::id,
>  MObject::kNullObj,
>  &stat);
>addAttribute(mPoseDataList);
>
>
> So now I want to set that in Python, but I'm not sure how too. Anyone run 
> into this before?
>

-- 
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/03035e4d-77fe-4ad4-88be-902e6248c70b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] How to us Custom MPxData from cpp in python.

2017-02-22 Thread Cameron Fulton
Hi all,

So I have a custom data type that I create in cpp that I use for an 
attribute on a custom node. My custom data type is pretty straight forward:
class BlindData : public MPxData
{


 public:
BlindData();
virtual ~BlindData();


  /**
   * Copy the local data from a similar data object
   *
   * @param MPxData
   *   Data object to copy from.
   */
  virtual void copy(const MPxData&);


  MStatus
  readBinary(istream& in, unsigned int length);


  MStatus
  writeBinary(ostream& out);


  MTypeId typeId() const;


  MString name() const;

  static MString typeName;
  static MTypeId id;
  static void* creator();


  std::vector m_data;
};

And then I just use that as a type for my attr on my node
  MFnTypedAttribute tAttr;
  MStatus stat;

blindDataAttr = tAttr.create("blindData",
 "blind",
 BlindData::id,
 MObject::kNullObj,
 &stat);
   addAttribute(mPoseDataList);


So now I want to set that in Python, but I'm not sure how too. Anyone run 
into this before?

-- 
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/3262f210-7b6e-4a01-a9fe-fb238dd43a19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Subprocess and deadlock

2017-02-22 Thread Justin Israel
I am not 100% sure on windows, but I will make a guess. It might be because
when you are using a pipe you are having the child inherit the file
descriptor (regardless of whether close_fds is used or works on windows).
The child process is looping and writing on stdout (the inherited fd). When
the parent process (Maya) closes it may want to wait for the child to
terminate, but the child won't terminate because it has an open pipe and
nothing has closed it. This would be completely independent from how you
are using a daemon thread. It just means your main process wont wait for
that thread to end, but processes are a different story.

You may want to experimental with trying to ensure you can close the pipe.
Does this have any different behaviour for you on Windows? It may not.

pipe = tempfile.TemporaryFile()
popen = subprocess.Popen(
["c:/python27/python.exe", "-u", "-c", child],
stdout=pipe
)
pipe.close()

If not, it could also be a combination of that and how windows handles
process groups (detach?). Maybe this SO answer might help on Windows in
order to manage the child process when the parent terminates:
http://stackoverflow.com/a/12942797/496445

As a workaround if it becomes to difficult to resolve, you could try
avoiding the inheriting of file descriptors altogether and see if it works
for you by using something like a named pipe, and passing the string name
argument to the child so it can open for reading or create for writing.

Justin


On Thu, Feb 23, 2017 at 6:37 AM Marcus Ottosson 
wrote:

> Here’s another one I fully expected to work; replacing PIPE with a regular
> file.
>
> import subprocessimport threadingimport tempfile
>
> child = """\
> import time
>
> while True:
> time.sleep(1)
> print("child: Still running..")
>
> """
>
> pipe = tempfile.TemporaryFile()
> popen = subprocess.Popen(
> ["c:/python27/python.exe", "-u", "-c", child],
> stdout=pipe
> )
>
> My theory was that perhaps Maya has mutilated PIPE for it’s own benefit.
> But alas, still hangs..
> ​
>
> On 22 February 2017 at 17:34, Christopher Crouzet <
> christopher.crou...@gmail.com> wrote:
>
> It's common when doing multiprocessing to have things working when they
> shouldn't in theory (I remember stumbling on a few such examples on
> StackOverflow, and writing many myself). This can be due to the order in
> which operations are being executed on either processes, the size of the
> inter-process messages, and whatnot. This also makes debugging a pain
> because reproducing some issues can be based on luck. So if I were you, I
> wouldn't put too much weight on different behaviours coming from other
> softwares.
>
>
> On 23 February 2017 at 00:27, Marcus Ottosson 
> wrote:
>
> That sounds logical, but the theory doesn't hold when considering it works
> with Python standalone and with Houdini. :(​
>
> --
> 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/CAFRtmOBX--vbvpOzUDP%2BsiX04MpT-yBMaj6DXwao2sk%3DFz6nPw%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> --
> Christopher Crouzet
> *https://christophercrouzet.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/msgid/python_inside_maya/CANuKW51e42hnVhzWTYGMuBy49pRxLQWyU6VSK_nQtno1vzUq2Q%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> --
> *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/msgid/python_inside_maya/CAFRtmODENpMQFw9U7Q7fugFmPsaFWR3jKjMfZas-pXf1saAw3g%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optou

Re: [Maya-Python] xform rotate object space

2017-02-22 Thread Chad Fox
Hi Mathew

Can you share more information on the transforms and hierarchy of the
object you are trying to transform? Eg. What are its parent's world space
rotation values, The object's current rotation and rotation order.

Also, it may help us help you if we could know why you need or are
expecting those specific final values.

Perhaps the values you are expecting are for a rotation order different
than the object that is being tested?

Let us know.

Chad


On Feb 21, 2017 6:04 PM, "Mathew Schwartz"  wrote:

When having an object selected, like a newly created box, performing the
command:

cmds.xform(ro=(10,0,30), os=True)

gives the same result as

cmds.xform(ro=(10,0,30), ws=True)

Both of them show the object rotation is 10,0,30 when querying the
respective transformations.
I am trying to rotate in object space, 10 in x, then 30 in z.  The final
rotation angles should be

x = 8.68220390105
y = -4.98092532193
z = 29.6216518752

when using

cmds.xform(ro=(10,0,30), os=True)
cmds.xform(ro=True, ws=True, query=True)

I tried using the euler flag, relative, etc.  but can not get the correct
transformation.  What am I doing wrong?

-- 
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/CADiWwnTB2GVZGGLLhAbwcnBQTdTrn
S64PR5F7P76z4%3DpCvu2Dg%40mail.gmail.com

.
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/CAJ4oLs4ka8%3D0%3DHfFCrWgs%2BDE%3D9Hd8uZ7UbefA-cc%3D%3Dyh%3DO24Dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Subprocess and deadlock

2017-02-22 Thread Marcus Ottosson
Here’s another one I fully expected to work; replacing PIPE with a regular
file.

import subprocessimport threadingimport tempfile

child = """\
import time

while True:
time.sleep(1)
print("child: Still running..")

"""

pipe = tempfile.TemporaryFile()
popen = subprocess.Popen(
["c:/python27/python.exe", "-u", "-c", child],
stdout=pipe
)

My theory was that perhaps Maya has mutilated PIPE for it’s own benefit.
But alas, still hangs..
​

On 22 February 2017 at 17:34, Christopher Crouzet <
christopher.crou...@gmail.com> wrote:

> It's common when doing multiprocessing to have things working when they
> shouldn't in theory (I remember stumbling on a few such examples on
> StackOverflow, and writing many myself). This can be due to the order in
> which operations are being executed on either processes, the size of the
> inter-process messages, and whatnot. This also makes debugging a pain
> because reproducing some issues can be based on luck. So if I were you, I
> wouldn't put too much weight on different behaviours coming from other
> softwares.
>
>
> On 23 February 2017 at 00:27, Marcus Ottosson 
> wrote:
>
>> That sounds logical, but the theory doesn't hold when considering it
>> works with Python standalone and with Houdini. :(​
>>
>> --
>> 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/CAFRtmOBX--vbvpOzUDP%2BsiX04MpT-
>> yBMaj6DXwao2sk%3DFz6nPw%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Christopher Crouzet
> *https://christophercrouzet.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/
> msgid/python_inside_maya/CANuKW51e42hnVhzWTYGMuBy49pRxL
> QWyU6VSK_nQtno1vzUq2Q%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*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/msgid/python_inside_maya/CAFRtmODENpMQFw9U7Q7fugFmPsaFWR3jKjMfZas-pXf1saAw3g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Subprocess and deadlock

2017-02-22 Thread Christopher Crouzet
It's common when doing multiprocessing to have things working when they
shouldn't in theory (I remember stumbling on a few such examples on
StackOverflow, and writing many myself). This can be due to the order in
which operations are being executed on either processes, the size of the
inter-process messages, and whatnot. This also makes debugging a pain
because reproducing some issues can be based on luck. So if I were you, I
wouldn't put too much weight on different behaviours coming from other
softwares.


On 23 February 2017 at 00:27, Marcus Ottosson 
wrote:

> That sounds logical, but the theory doesn't hold when considering it works
> with Python standalone and with Houdini. :(​
>
> --
> 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/CAFRtmOBX--vbvpOzUDP%2BsiX04MpT-yBMaj6DXwao2sk%
> 3DFz6nPw%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Christopher Crouzet
*https://christophercrouzet.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/msgid/python_inside_maya/CANuKW51e42hnVhzWTYGMuBy49pRxLQWyU6VSK_nQtno1vzUq2Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Subprocess and deadlock

2017-02-22 Thread Marcus Ottosson
That sounds logical, but the theory doesn't hold when considering it works
with Python standalone and with Houdini. :(​

-- 
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/CAFRtmOBX--vbvpOzUDP%2BsiX04MpT-yBMaj6DXwao2sk%3DFz6nPw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Subprocess and deadlock

2017-02-22 Thread Christopher Crouzet
If I am not mistaken, when a parent process is trying to exit normally,
that is with no exception or such forced termination, then it needs to wait
for all of its child processes to be joined. If one of them is blocked,
then it won't join.


On 23 February 2017 at 00:13, Marcus Ottosson 
wrote:

> Thanks Christopher.
>
> Maybe readline() is one of these, meaning that it won’t return until it
> receives something, which might never happen in your case after exiting
> Maya?
>
> That’s right, readline() blocks until something is passed, via send() in
> this case. The for line in iter(out.readline, b""): is an infinite loop
> in this case, but as with any infinite loop in a thread I would have
> expected it to break when the thread is shutdown.
>
> For example, this works fine.
>
> import sysimport timeimport subprocessimport threading
> def _listen():
> while True:
> print("Still running..")
> time.sleep(1)
>
> thread = threading.Thread(target=_listen)
> thread.daemon = True
> thread.start()
>
> Both cases also work well in Houdini, and standalone in a vanilla Python
> process. This symptoms seem highly Maya specific, though I suspect it’s
> only more sensitive to something I’m doing wrong. Such as shutting down a
> thread that is waiting to hear back from the OS about a read from a file.
>
> What’s more, in Maya 2016+ Maya unfreezes as soon as I close the external
> terminal that appears. With 2015 it does not.
>
> Mystery.
> ​
>
> On 22 February 2017 at 17:00, Christopher Crouzet <
> christopher.crou...@gmail.com> wrote:
>
>> Disclaimer: this might be totally unrelated to your problem! :)
>>
>> A common source of deadlocks when using the `multiprocessing` module (or
>> anything related to IPC) comes from calling receiving/sending functions
>> that are blocking. Maybe `readline()` is one of these, meaning that it
>> won't return until it receives something, which might never happen in your
>> case after exiting Maya?
>>
>> A common solution is to wrap the body of the process function
>> (`_listen()` in your case) into an infinite loop and then receive any
>> incoming message only if the inter-process connection is not empty. The
>> infinite loop is exited when the process receives a sentinel/stop message
>> (usually sent from the parent process) to tell it to quit.
>>
>> Not sure if this can be applied to your code though.
>>
>>
>> On 22 February 2017 at 23:22, Marcus Ottosson 
>> wrote:
>>
>>> close_fds isn’t supported on Windows apparently.
>>>
>>> # ValueError: close_fds is not supported on Windows platforms if you 
>>> redirect stdin/stdout/stderr #
>>>
>>> DETACHED_PROCESS didn’t work either unfortunately, but it was worth a
>>> shot. I feel it must be related to this somehow. I’ve tried
>>> CREATE_NO_WINDOW and CREATE_NEW_PROCESS_GROUP as well without avail.
>>>
>>> Here’s
>>> .aspx)
>>> all possible creation flags for reference.
>>>
>>> Any other ideas?
>>>
>>> Best,
>>> Marcus
>>> ​
>>>
>>> --
>>> 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/CAFRtmOATTheY4DsCQbrLugUQxJgq7OSyNdHT
>>> UY%3Db%3DWvU1kZ_HQ%40mail.gmail.com
>>> 
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Christopher Crouzet
>> *https://christophercrouzet.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/CANuKW523MnX4g3AOATrFuqajJb6w4S1p2y5K
>> 2ATqd89Qwpfoaw%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *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/
> msgid/python_inside_maya/CAFRtmOCzbHgea%3DDTpXB4Haf0q0z%
> 3DDHUNAjAim

Re: [Maya-Python] Subprocess and deadlock

2017-02-22 Thread Marcus Ottosson
Ok, I might have found a way to break this down further.

This also freezes Maya on exit, until I close the new console window.

import subprocessimport threading

child = """\
import time

while True:
time.sleep(1)
print("child: Still running..")

"""

popen = subprocess.Popen(
["c:/python27/python.exe", "-u", "-c", child],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE
)

What’s more, if I remove the stdout=PIPE and stdin=PIPE, all is well and
nothing hangs.

Whyyy? :(
​

On 22 February 2017 at 17:13, Marcus Ottosson 
wrote:

> Thanks Christopher.
>
> Maybe readline() is one of these, meaning that it won’t return until it
> receives something, which might never happen in your case after exiting
> Maya?
>
> That’s right, readline() blocks until something is passed, via send() in
> this case. The for line in iter(out.readline, b""): is an infinite loop
> in this case, but as with any infinite loop in a thread I would have
> expected it to break when the thread is shutdown.
>
> For example, this works fine.
>
> import sysimport timeimport subprocessimport threading
> def _listen():
> while True:
> print("Still running..")
> time.sleep(1)
>
> thread = threading.Thread(target=_listen)
> thread.daemon = True
> thread.start()
>
> Both cases also work well in Houdini, and standalone in a vanilla Python
> process. This symptoms seem highly Maya specific, though I suspect it’s
> only more sensitive to something I’m doing wrong. Such as shutting down a
> thread that is waiting to hear back from the OS about a read from a file.
>
> What’s more, in Maya 2016+ Maya unfreezes as soon as I close the external
> terminal that appears. With 2015 it does not.
>
> Mystery.
> ​
>
> On 22 February 2017 at 17:00, Christopher Crouzet <
> christopher.crou...@gmail.com> wrote:
>
>> Disclaimer: this might be totally unrelated to your problem! :)
>>
>> A common source of deadlocks when using the `multiprocessing` module (or
>> anything related to IPC) comes from calling receiving/sending functions
>> that are blocking. Maybe `readline()` is one of these, meaning that it
>> won't return until it receives something, which might never happen in your
>> case after exiting Maya?
>>
>> A common solution is to wrap the body of the process function
>> (`_listen()` in your case) into an infinite loop and then receive any
>> incoming message only if the inter-process connection is not empty. The
>> infinite loop is exited when the process receives a sentinel/stop message
>> (usually sent from the parent process) to tell it to quit.
>>
>> Not sure if this can be applied to your code though.
>>
>>
>> On 22 February 2017 at 23:22, Marcus Ottosson 
>> wrote:
>>
>>> close_fds isn’t supported on Windows apparently.
>>>
>>> # ValueError: close_fds is not supported on Windows platforms if you 
>>> redirect stdin/stdout/stderr #
>>>
>>> DETACHED_PROCESS didn’t work either unfortunately, but it was worth a
>>> shot. I feel it must be related to this somehow. I’ve tried
>>> CREATE_NO_WINDOW and CREATE_NEW_PROCESS_GROUP as well without avail.
>>>
>>> Here’s
>>> .aspx)
>>> all possible creation flags for reference.
>>>
>>> Any other ideas?
>>>
>>> Best,
>>> Marcus
>>> ​
>>>
>>> --
>>> 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/CAFRtmOATTheY4DsCQbrLugUQxJgq7OSyNdHT
>>> UY%3Db%3DWvU1kZ_HQ%40mail.gmail.com
>>> 
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Christopher Crouzet
>> *https://christophercrouzet.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/CANuKW523MnX4g3AOATrFuqajJb6w4S1p2y5K
>> 2ATqd89Qwpfoaw%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *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 A

Re: [Maya-Python] Subprocess and deadlock

2017-02-22 Thread Marcus Ottosson
Thanks Christopher.

Maybe readline() is one of these, meaning that it won’t return until it
receives something, which might never happen in your case after exiting
Maya?

That’s right, readline() blocks until something is passed, via send() in
this case. The for line in iter(out.readline, b""): is an infinite loop in
this case, but as with any infinite loop in a thread I would have expected
it to break when the thread is shutdown.

For example, this works fine.

import sysimport timeimport subprocessimport threading
def _listen():
while True:
print("Still running..")
time.sleep(1)

thread = threading.Thread(target=_listen)
thread.daemon = True
thread.start()

Both cases also work well in Houdini, and standalone in a vanilla Python
process. This symptoms seem highly Maya specific, though I suspect it’s
only more sensitive to something I’m doing wrong. Such as shutting down a
thread that is waiting to hear back from the OS about a read from a file.

What’s more, in Maya 2016+ Maya unfreezes as soon as I close the external
terminal that appears. With 2015 it does not.

Mystery.
​

On 22 February 2017 at 17:00, Christopher Crouzet <
christopher.crou...@gmail.com> wrote:

> Disclaimer: this might be totally unrelated to your problem! :)
>
> A common source of deadlocks when using the `multiprocessing` module (or
> anything related to IPC) comes from calling receiving/sending functions
> that are blocking. Maybe `readline()` is one of these, meaning that it
> won't return until it receives something, which might never happen in your
> case after exiting Maya?
>
> A common solution is to wrap the body of the process function (`_listen()`
> in your case) into an infinite loop and then receive any incoming message
> only if the inter-process connection is not empty. The infinite loop is
> exited when the process receives a sentinel/stop message (usually sent from
> the parent process) to tell it to quit.
>
> Not sure if this can be applied to your code though.
>
>
> On 22 February 2017 at 23:22, Marcus Ottosson 
> wrote:
>
>> close_fds isn’t supported on Windows apparently.
>>
>> # ValueError: close_fds is not supported on Windows platforms if you 
>> redirect stdin/stdout/stderr #
>>
>> DETACHED_PROCESS didn’t work either unfortunately, but it was worth a
>> shot. I feel it must be related to this somehow. I’ve tried
>> CREATE_NO_WINDOW and CREATE_NEW_PROCESS_GROUP as well without avail.
>>
>> Here’s
>> .aspx)
>> all possible creation flags for reference.
>>
>> Any other ideas?
>>
>> Best,
>> Marcus
>> ​
>>
>> --
>> 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/CAFRtmOATTheY4DsCQbrLugUQxJgq7OSyNdHT
>> UY%3Db%3DWvU1kZ_HQ%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Christopher Crouzet
> *https://christophercrouzet.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/
> msgid/python_inside_maya/CANuKW523MnX4g3AOATrFuqajJb6w4
> S1p2y5K2ATqd89Qwpfoaw%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*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/msgid/python_inside_maya/CAFRtmOCzbHgea%3DDTpXB4Haf0q0z%3DDHUNAjAimZMHjae_KTh90A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Subprocess and deadlock

2017-02-22 Thread Christopher Crouzet
Disclaimer: this might be totally unrelated to your problem! :)

A common source of deadlocks when using the `multiprocessing` module (or
anything related to IPC) comes from calling receiving/sending functions
that are blocking. Maybe `readline()` is one of these, meaning that it
won't return until it receives something, which might never happen in your
case after exiting Maya?

A common solution is to wrap the body of the process function (`_listen()`
in your case) into an infinite loop and then receive any incoming message
only if the inter-process connection is not empty. The infinite loop is
exited when the process receives a sentinel/stop message (usually sent from
the parent process) to tell it to quit.

Not sure if this can be applied to your code though.


On 22 February 2017 at 23:22, Marcus Ottosson 
wrote:

> close_fds isn’t supported on Windows apparently.
>
> # ValueError: close_fds is not supported on Windows platforms if you redirect 
> stdin/stdout/stderr #
>
> DETACHED_PROCESS didn’t work either unfortunately, but it was worth a
> shot. I feel it must be related to this somehow. I’ve tried
> CREATE_NO_WINDOW and CREATE_NEW_PROCESS_GROUP as well without avail.
>
> Here’s
> .aspx)
> all possible creation flags for reference.
>
> Any other ideas?
>
> Best,
> Marcus
> ​
>
> --
> 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/CAFRtmOATTheY4DsCQbrLugUQxJgq7
> OSyNdHTUY%3Db%3DWvU1kZ_HQ%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Christopher Crouzet
*https://christophercrouzet.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/msgid/python_inside_maya/CANuKW523MnX4g3AOATrFuqajJb6w4S1p2y5K2ATqd89Qwpfoaw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Subprocess and deadlock

2017-02-22 Thread Marcus Ottosson
close_fds isn’t supported on Windows apparently.

# ValueError: close_fds is not supported on Windows platforms if you
redirect stdin/stdout/stderr #

DETACHED_PROCESS didn’t work either unfortunately, but it was worth a shot.
I feel it must be related to this somehow. I’ve tried CREATE_NO_WINDOW and
CREATE_NEW_PROCESS_GROUP as well without avail.

Here’s
.aspx)
all possible creation flags for reference.

Any other ideas?

Best,
Marcus
​

-- 
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/CAFRtmOATTheY4DsCQbrLugUQxJgq7OSyNdHTUY%3Db%3DWvU1kZ_HQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Subprocess and deadlock

2017-02-22 Thread Marcus Ottosson
Thanks Alok, I did experiment with both of those. Will try this again next.

On 22 Feb 2017 11:30, "Alok Gandhi"  wrote:

> And for completeness also pass  creationflags=DETACHED_PROCESS in Popen().
>
> On Wed, Feb 22, 2017 at 7:28 PM, Alok Gandhi 
> 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 
>> 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 
>>> 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
>>> 
>>> .
>>>
>>> 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
> 
> .
> 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.


Re: [Maya-Python] Subprocess and deadlock

2017-02-22 Thread Alok Gandhi
And for completeness also pass  creationflags=DETACHED_PROCESS in Popen().

On Wed, Feb 22, 2017 at 7:28 PM, Alok Gandhi 
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 
> 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 
>> 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
>> 
>> .
>>
>> 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/CAPaTLMR37jwOsJSW9MenrX2i4KsrGbEtdyZBCdW1zKdWewhRng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Subprocess and deadlock

2017-02-22 Thread Alok Gandhi
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 
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 
> 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/
> msgid/python_inside_maya/CAFRtmOA_eDnLSUr_v89jxS6Qa%
> 3DUNEGc0eF%2B0ygHbqTo-E03Sgw%40mail.gmail.com
> 
> .
>
> 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/CAPaTLMRu%2BUnL5p4n6YYe2F7C0rGJRWASZfSjnBGRX-0mzyOWig%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Subprocess and deadlock

2017-02-22 Thread Marcus Ottosson
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 
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/msgid/python_inside_maya/CAFRtmOA_eDnLSUr_v89jxS6Qa%3DUNEGc0eF%2B0ygHbqTo-E03Sgw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] Subprocess and deadlock

2017-02-22 Thread Marcus Ottosson
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

-- 
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/CAFRtmOAy2ViO-ZfoNBCju-yjxM5077pxp2xsaQA%2BeaEzuXaL7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.