Having multiple instances of a single application start a single instance of another one
I have two applications that should work together, let's call them A and B. The first time A starts, it should open a B process and start communicating with it. All other times an A instance starts it should simply talk with the B that already is open. The problem here is, if I start say 40 A applications at once... how do I check if a B is open "fast enough" so that the other A's (not the first one) won't spawn new B's? Im programming this in windows and am currently using the horrible solution in A if not win32gui.FindWindow(None, "Name of B"): spawn_B_here() This only works well if there is a small time between the A's started first... What would the best solution for my problem be? /buffis -- http://mail.python.org/mailman/listinfo/python-list
Re: Having multiple instances of a single application start a single instance of another one
Troy Melhase wrote: >> The first time A starts, it should open a B process and start >> communicating with it. All other times an A instance starts it should >> simply talk with the B that already is open. > > B should write its process id to a location known by both > applications. When A starts, it should read that PID from the file > and attempt to communicate with the process having that PID. > > When B starts, it should also check for the file. If it's found and > if the PID in it is present in the process table, then B should exit. > Otherwise, it should start normally and write its own PID to the file. Three very simple questions then. 1. How do I find out a running applications process ID 2. How do I check if a process ID is bound to a running application. 3. There won't be any issues with different applications trying to read and write the same file doing this? /buffis -- http://mail.python.org/mailman/listinfo/python-list
Recreating a char array from a pointer
I have an application that has to send a string as a pointer to memory, and then another one that has to retriece it and fetch the string. Converting the string to an array and sending the pointer was easy import array a=array.array("c","mytextgoeshere") my_pointer = a.buffer_info()[0] But then I tried to get the data back... and I just can't find out how. I ended up writing a C module for this that works fine in linux, but this application is meant for windows and I just can't get C-modules to compiler there correctly since I suck at windows. The relevant code from the module is static PyObject * pointrtostr_casttostr(PyObject *self, PyObject *args) { char *mystr; long int p; if (!PyArg_ParseTuple(args, "l", &p)) return NULL; mystr = (char*)p; return Py_BuildValue("s", mystr); } My question is... can I do the above code in python without involving C since it is quite a big hassle to have to go through the module building in windows? :/ /buffis -- http://mail.python.org/mailman/listinfo/python-list
Re: Recreating a char array from a pointer
Oh, nice Im running 2.4 but im gonna download it and give it a try then Thanks! Thomas Heller wrote: > buffinator schrieb: >> I have an application that has to send a string as a pointer to memory, >> and then another one that has to retriece it and fetch the string. >> Converting the string to an array and sending the pointer was easy >> >> import array >> a=array.array("c","mytextgoeshere") >> my_pointer = a.buffer_info()[0] >> >> >> But then I tried to get the data back... and I just can't find out how. >> I ended up writing a C module for this that works fine in linux, but >> this application is meant for windows and I just can't get C-modules to >> compiler there correctly since I suck at windows. >> >> The relevant code from the module is >> >> static PyObject * >> pointrtostr_casttostr(PyObject *self, PyObject *args) >> { >> char *mystr; >> long int p; >> >> if (!PyArg_ParseTuple(args, "l", &p)) >>return NULL; >> >> mystr = (char*)p; >> return Py_BuildValue("s", mystr); >> } >> >> My question is... can I do the above code in python without involving C >> since it is quite a big hassle to have to go through the module building >> in windows? :/ > > You can use the ctypes package for this. It is in the standard library in > Python 2.5, > for older versions it is a separate download. > > Thomas > -- http://mail.python.org/mailman/listinfo/python-list