Re: attach to process by pid?
On Mar 8, 7:49 pm, James Mills wrote: > On Wed, Mar 9, 2011 at 9:20 AM, Danny Shevitz wrote: > > Is there any way to attach to an already running process by pid? I want to > > send > > commands from python to an application that is already running. I don't > > want to > > give the command name to subprocess.Popen. > > Unless I'm missing something here I don't see how you could > achieve communication with another process unless that > process has some kind of communication(s) interface; eg: > * some kind of listening socket > * some kind of I/O (pipe, stdin/stdout) > > cheers > James > > -- > -- James Mills > -- > -- "Problems are solved by method" Have a look at the SIMPL toolkit. http://www.icanprogram.com/06py/lesson1/lesson1.html This should be able to do exactly what you want. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: attach to process by pid?
On Mar 9, 1:28 pm, Danny Shevitz wrote: > > Have a look at the SIMPL toolkit. > > http://www.icanprogram.com/06py/lesson1/lesson1.html > > > > > This should be able to do exactly what you want. > > > bob > > Does this work on Mac OS X? > > thanks, > Danny I'm not aware of any ports of the SIMPL toolkit to the MacOSX. However, the core SIMPL library doesn't depend on anything facier than a named pipe or fifo and shared memory. If you'd like to be the test bed I can ask around the SIMPL project to see if anyone wants to take a crack at porting the SIMPL-Python stuff to MacOSX. bob -- http://mail.python.org/mailman/listinfo/python-list
help porting an open source toolkit to Mac and Windows/Cygwin
I am the facilitator for the SIMPL open source project (http:// www.icanprogram.com/simpl). The SIMPL toolkit project started over 10 years ago as a way to bring Send/Receive/Reply (QNX style) messaging to Linux. A SIMPL application consists of two or more interacting SIMPL modules. Those modules can be written in any number of languages including Python, C, C++, JAVA, Tcl/Tk and soon PHP. Modules written in different languages can be mixed in a SIMPL application (some Python and C examples are here http://www.icanprogram.com/06py/lesson1/lesson1.html). SIMPL modules can be distributed on a single node or spread across a network often without even a recompile. Until now a SIMPL network had to contain at least one Linux node. This is about to change. Recently work (http://icanprogram.ca/simpl/ simpl.self.html) has allowed the SIMPL core library to be successfully compiled and run on a Mac. We'd love to do the same with Windows/ Cygwin. Over the years the Python-SIMPL webpages have always been amongst the top for web hits on the SIMPL website every month. So despite its limitations Python-SIMPL is apparently very popular in the Python community. We'd love to extend the Mac work to include the Python- SIMPL library and thereby make the Mac a full Python-SIMPL citizen. If the work with Windows/Cygwin progresses along a similar path to the Mac effort, we'd love to do the same with the Python-SIMPL library there. Our goal is to have three fully functional Python-SIMPL libraries: Linux, Mac and Windows. We are looking for Python volunteers to help make this happen. If you are interested don't hesitate to contact me offlist or make contact on the SIMPL project mailing list. Thanks. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: python logging multiple processes to one file (via socket server)
On Oct 27, 6:09 am, Gelonida N wrote: > Hi, > > I have a rather 'simple' problem. > Logging from multiple processes to the same file AND be sure, that no > log message is lost, > > 1.) Log multiple processes to one file: > -- > > I have a python program, which I want to log, but which forks several times. > > Due to the forking logging to files with the default logging.FileHandler > seems out of question. > > It seems, that I could use a SocketHandler, which collects data from all > different processes and logs then to one file. > > Does anybody have a working example. > > 2.) Ensure, that no log message is lost. > -- > If I understood the doc of the SocketHandler, then > it will drop messages if the socket handler is not available. > > However for my current activity I would prefer, that it aborts if it > cannot connect to the socket and that it blocks if the log server > doesn't handle the sent data fast enough. > > Is this possible. > > Thanlks a lot in advance. > > What I found so > far:http://docs.python.org/howto/logging-cookbook.html#logging-to-a-singl... > > It states: > "The following section documents this approach in more detail and > includes a working socket receiver which can be used as a starting point > for you to adapt in your own applications." > > Somehow I have a mental block though and fail to see the 'following > section'. > > I also foundhttp://code.google.com/p/python-loggingserver/and ran > first tests. > > However it seems, that this server stops logging my application after > about 128 log entries. (the number varies and is not necessarily exactly > 128), whereas the console loggier continues logging. > > I'm not really show why and would prefer a simpler example first. > > Thanks in advance for any code example, idea, link, comment. You might want to check out the SIMPL toolkit (http:// www.icanprogram.com/06py/main.html). A SIMPL receiver will "naturally" queue and serialize messages from multiple senders. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some IPC pointers
On Nov 30, 4:03 pm, Andrew Berg wrote: > I've done some research, but I'm not sure what's most appropriate for my > situation. What I want to do is have a long running process that spawns > processes (that aren't necessarily written in Python) and communicates > with them. The children can be spawned at any time and communicate at > any time. Being able to communicate with non-local processes would be > nice, but is not necessary. The implementation needs to be > cross-platform, but child processes will use the same OS as the parent > during runtime. > I don't think I'll ever need to transfer anything complicated or large - > just strings or possibly tuples/lists. I'd rather not go outside the > standard library (but I'd consider it). I don't need to worry about > compatibility with older Python versions; if it only works with Python > 3.2, that's not a problem. > I'm thinking sockets, but perhaps there's something simpler/easier. > > -- > CPython 3.2.2 | Windows NT 6.1.7601.17640 | Thunderbird 7.0 You might want to take a look at the SIMPL toolkit. http://www.icanprogram.com/06py/lesson1/lesson1.html SIMPL modules can be written (and mixed) in any number of supported languages including Python, C, C++, JAVA, Tcl/Tk or PHP. Non local communication is handled by generic surrogates. Because of this surrogate architecture SIMPL modules can often be tested locally and then deployed into the cloud without any changes. bob -- http://mail.python.org/mailman/listinfo/python-list
Ann: Python-SIMPL online tutorial updated to include examples of cloud interfacing
The Python-SIMPL tutorial is at: http://www.icanprogram.com/06py/lesson1/lesson1.html Several lessons (3,4, 6 &7) have been enhanced to include examples of Python apps interfacing to the cloud housed on a Linode. The open source SIMPL toolkit provides a very lean Send/Receive/Reply (QNX style) messaging library. A SIMPL application consists of 2 or more interacting SIMPL modules. A SIMPL module can be written in any number of supported languages including Python, C, C++, JAVA, Tcl/Tk or PHP. More importantly they can be mixed in any given SIMPL application. Through the use of generic surrogates, SIMPL modules are "naturally" cloud aware often without even a recompile. In this tutorial a SIMPL receiver module (written in C) is exported unchanged to the Linode cloud. Examples of Python modules connecting to this Linode hosted module via the SIMPL TCP/IP surrogates, SIMPL tclSurrogate daemon, and Python-CGI are all illustrated. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: IPC with multiprocessing.connection
On Dec 22, 3:27 pm, Andrew Berg wrote: > I'm trying to set up a system where my main program launches external > programs and then establishes connections to them via named pipes or > Unix domain sockets (depending on platform) with > multiprocessing.connection.Listener. The issue I'm having is with the > accept() method. If there is nothing on the other side of the > pipe/socket, it just hangs. Connection objects have a poll() method that > can timeout, but I see no way to continue the program if there's no > initial connection. What I'd like to do is let it time out if there's > nothing on the other side. > I'm pretty new to the multiprocessing module (and IPC in general), so I > could've easily missed something. > > -- > CPython 3.2.2 | Windows NT 6.1.7601.17640 You might want to check out the code samples at: http://www.icanprogram.com/06py/lesson1/lesson1.html bob -- http://mail.python.org/mailman/listinfo/python-list
significant release for SIMPL project's Python extension
The SIMPL project (http://www.icanprogram.com/simpl) aims to bring the simplicity and power of the Send/Receive/Reply messaging (first pioneered by QNX) to the Linux world. SIMPL modules are themselves Linux executables and can be written in any number of languages now (C, C++, Tcl/Tk and Python). A SIMPL application consists of one or more of these modules interacting in a single SIMPL sandbox.A SIMPL application can consist of SIMPL modules written in a mixture of supported languages. In addtion SIMPL applications can be spread across a network seamlessly through the use of TCP/IP or RS232 surrogates.In most cases this redeployment can occur without an code change or recompilation. Python is one of the newer languages to be added to the SIMPL family, but it is already attracting significant attention.An online course on SIMPL-Python offered for no fees by iCanProgram (http:// www.icanprogram.com/06py/main.html) consistently gets the highest number of web hits in any given month. Up until now SIMPL-Python modules could already be built for deployment on a Linux OS. Now SIMPL-Python modules can be written for a non Linux OS and interact with a SIMPL application using the tclSurrogate (TCP/IP) protocol which SIMPL supports.This means that a Python script running under Windows can now participate seamlessly in a SIMPL application running on a Linux network. In addition SIMPL-Python web scripts can also now participate seamlessly in a SIMPL application.This feature greatly extends the reach of SIMPL-Python into the realm of web interfaces and web applications. The easiest way to get aquainted with the SIMPL-Python toolset is to download one of its self installing archives for Linux.These are safely deployed in /tmp to allow full exploration with an option to permanently install the release in a directory of your choosing. SIMPL-Python self installing archive - http://www.icanprogram.com/simpl/python.self.html SIMPL-Python course self installing archive - http://www.icanprogram.com/pythoncourse.self.html the SIMPL project team -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Application Server
On Jan 27, 11:23 pm, Adi Eyal wrote: > Hi All > > Could anyone recommend a python application server? My application > consists mainly of long running background processes that need to > communicate with each other. Features on my wishlist include, process > pooling (each process will in general be stateless), monitoring, > scheduling and a framework for inter-process communication. Ideally, I > would also like to be able to cluster the app server if the need > arises. I have never used Zope or Webware, but my impression is that > these servers are focused on web applications with a short > request-response cycle. My usage will be different since my processes > will be triggered by certain events and then continue running until > they complete, without sending any response at all but possibly > spawning off additional processes in a workflow. > > I hope my description has been clear. Does such an application server > exist for python? > > Thanks in advance > Adi You might want to look into the SIMPL project stuff (http:// www.icanprogram.com/simpl). In particular there is a framework (SIMPL calls them softwareICs) called a proxy which sounds like exactly what you might want. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling Python-tk code from C/C++
On Jan 27, 12:29 pm, "Gabriel Genellina" wrote: > En Tue, 27 Jan 2009 07:42:01 -0200, Rajorshi Biswas > escribió: > > > Hello all, This is my first post to this mailing list. Our requirement > > is to invoke a Tkinter python panel from a C++ GUI app where both GUI > > windows would run in 2 separate threads. We have written a sample PyQt > > application which calls this Tk panel using something like this:class > > TkPanel(threading.Thread):def run(self): # call showPaneldef > > showPanel():# create window = Tk.Tk() window.mainloop()def start():t = > > TkPanel()t.start()Now we call this from our main python code:def > > startPanel(self): import tkPanel tkPanel.start() # this calls > > tkwindow.mainloop() in a separate thread.This works absolutely fine when > > the invoking app is Python. > > From the above description I don't see where PyQt is involved. Do you > really want to mix Qt and Tk in the same application? I don't think they > could coexist... > -- > Gabriel Genellina Check out the SIMPL project (http://www.icanprogram.com/simpl). Using that toolkit you should be able to have your C++ module exchange a message with a separate Python/Tk/SIMPL module.This might do what you are after. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: convert the ip packet to and from RS-232 packet
On Feb 9, 8:13 am, Li Han wrote: > Hi, I need to use radio to connect two local ip network, each local > network has a server computer which connects to a radio with RS-232 > interface. I need to write a program to convert the local ip packet > into RS-232 packet, so the radio can send packetes to the remote > radio. I don't want to reinvent the wheel, is there anyone could give > me some suggestions? > Thank you! > Han You might want to check out the SIMPL toolkit. (http:// www.icanprogram.com/simpl). It come standard with an RS232 surrogate. This generic module will transparently transmit a SIMPL message via RS232 serial connection. Although this module is written in C, SIMPL itself fully supports Python as a language to create modules. bob -- http://mail.python.org/mailman/listinfo/python-list
upgrading my SIMPL Programming with Python nofee online course need some volunteer testers
SIMPL is an open source project which has been around for almost 10 years. It maintains a very compact interprocesss communication library which gives Linux developers the Send/Receive/Reply messaging paradigm first popularized by QNX almost 30 years ago. (http://www.icanprogram.com/simpl). SIMPL has had a Python shared library for almost 5 years now. I believe that the SIMPL-Python hooks are one of the underused gems in the SIMPL project. I also maintain a couple of nofee online courses including one whose subject is this Python interface into the SIMPL world (although I'm not the author of the lesson material). http://www.icanprogram.com/06py/main.html There is active work in the SIMPL project to bring two upgrades in the Python area. a) the ability to run Python code on Windows and seamlessly interface with a SIMPL application running under Linux b) the ability to interface to a SIMPL-Python application from a simple browser interface The plan is to enhance this course material with this new functionality just as soon as it arrives. Meanwhile I've been working to upgrade the course installation experience with a self installing archive. http://www.icanprogram.com/python.self.html I'm exactly the wrong person to debug this stuff as I'm not a Python programmer and I'm too close in to spot the obvious flaws. I'm looking for Python/Linux volunteers to give this stuff a spin and supply constructive criticism to help improve the student installation experience. Thanks in advance. bob SIMPL project coordinator PS. If anyone is interested in reading more about SIMPL and SIMPL-Python I'm the co-author of a recent book on the subject. Google Books has a free preview of many of the chapters. (see http://www.icanprogram.com/lulu.html). -- http://mail.python.org/mailman/listinfo/python-list
problem adding custom module in cgi script
Problem: Apache server serving an HTML file to a Firefox Browser containing a form and a CGI python CGI script. HTML works fine, meat of the CGI script works fine except that when a home grown and ordinarily functional module that is to be imported is added, the interpreter cannot find it. Running cgi.test() reveals that PYTHONPATH is correctly set. Still nada. Adding the sys.* stuff still nada. Items: Firefox Browser, Apache server, Python 2.5. === The CGI script: #! /usr/bin/python import cgi #cgi.test() import sys #sys.path.append("/myModulePath") #sys.path.insert(0, "/myModulePath") import myModule Problem here === httpd error_log excerpt: [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1] Traceback (most recent call last):, referer: http://192.168.1.1/nee.html [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1] File "/var/www/cgi-bin/noo.py", line 11, in , referer: http://192.168.1.1/nee.html [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1] import myModule, referer: http://192.168.1.1/nee.html [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1] ImportError: No module named myModule, referer: http://192.168.1.1/nee.html = Relevant lines from http.conf: ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" SetEnv PYTHONPATH /myModulePath PassEnv PYTHONPATH Thanks in advance for any pointers. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: problem adding custom module in cgi script
On Dec 11, 8:03 pm, bobicanprogram wrote: > Problem: > > Apache server serving an HTML file to a Firefox Browser containing a > form and > a CGI python CGI script. HTML works fine, meat of the CGI script works > fine > except that when a home grown and ordinarily functional module that is > to be > imported is added, the interpreter cannot find it. > > Running cgi.test() reveals that PYTHONPATH is correctly set. Still > nada. > Adding the sys.* stuff still nada. > > Items: Firefox Browser, Apache server, Python 2.5. > > === > > The CGI script: > #! /usr/bin/python > > import cgi > #cgi.test() > import sys > > #sys.path.append("/myModulePath") > #sys.path.insert(0, "/myModulePath") > import myModule Problem here > > === > httpd error_log excerpt: > [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1] Traceback > (most recent > call last):, referer:http://192.168.1.1/nee.html > [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1] > File "/var/www/cgi-bin/noo.py", line 11, in , > referer:http://192.168.1.1/nee.html > [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1] import > myModule, > referer:http://192.168.1.1/nee.html > [Wed Dec 10 13:39:46 2008] [error] [client 192.168.1.1] ImportError: > No module > named myModule, referer:http://192.168.1.1/nee.html > > = > Relevant lines from http.conf: > ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" > SetEnv PYTHONPATH /myModulePath > PassEnv PYTHONPATH > > Thanks in advance for any pointers. > > bob Solution found! The apache web server is running on a Linux box equipped with SELinux which was preventing apache from opening the required modules according to the SELinux troubleshoot browser which is available from the main menu under the administration moniker. Apache's error_log describes the problem as one of not being able to locate the said modules for import. This is misleading to say the least. Adjusting SELinux to allow this is the solution to the problem; this can be done under 'main menu/administration/ SELinux Management bob -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess to C program
On Dec 13, 10:09 pm, MRAB wrote: > Aaron Brady wrote: > > On Dec 13, 7:51 pm, Grant Edwards wrote: > >> On 2008-12-14, MRAB wrote: > > I am writing a C process and I want to read data from a file that I > write to in Python. I'm creating a pipe in Python, passing it to the > C process, and calling '_read'. It gives me error 9, bad file number. > > snip > meaning that 'ct' is -1, 'readfd' is 3, and 'errno' is 9. I want 'ct' > to be 11 at this point. Thanks in advance. > >>> It looks like the ids aren't system global. > >> They certainly aren't in Unix: Their a property of the process. > > >> -- > >> Grant > > > I'm not on Unix. It has to be possible somehow. Do I need to set > > permissions on the IDs? Are Stdin and Stdout my only options? Or > > does Popen prevent sharing IDs somehow? > > You'd be better off using sockets. You might also consider using SIMPL (http://www.icanprogram.com/simpl) SIMPL has had a Python interface for about 5 years now. There is an online tutorial here. (http://www.icanprogram.com/06py/main.html) In one of your responses you mentioned that you were not on Unix (and I presume Linux). SIMPL-Python has recently been extended to work transparently from a Windows OS as well. bob SIMPL project coordinator -- http://mail.python.org/mailman/listinfo/python-list
Re: c++ extension, problem passing argument
On Mar 13, 1:34 pm, Matteo wrote: > hmmm... looks like SWIG has a problem with double pointers. I googled > around a bit and found: > > http://osdir.com/ml/programming.swig/2003-02/msg00029.html > > anyone knows how to write a small wrapper to do the appropriate > dereferencing? If you can't solve your problem with SWIG you might still be able to accomplish what you set out to do with the SIMPL toolkit. (http:// www.icanprogram.com/simpl) There are lots of examples kicking around where a Python program exchanges data with a C (or C++) program. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Short-term python programming consultant - funds expire soon!
On Mar 10, 1:35 pm, Rob Clewley wrote: > Dear Pythonistas, > > Our open-source software project (PyDSTool) has money to hire an > experienced Python programmer on a short-term, per-task basis as a > technical consultant (i.e., no fringe benefits offered). The work can > be done remotely and will be paid after the satisfactory completion of > the objectives. The work must be completed by the end of April, when > the current funds expire. The basic work plan and design documents are > already laid out from previous work on these tasks, but the finer > details will be negotiable. We plan to pay approximately $2-3k per > task, depending on the exact code design and amount of time required. > > Prospective consultants could be professionals or students but must > have proven experience with SWIG and both python and numpy distutils, > and be willing to write a short document about the completed work for > future maintenance purposes. We have a template for a simple contract > and invoices can be relatively coarse-grained. As an open-source > project, all contributed code will be BSD licensed as part of our > project, although it will retain attribution of your authorship. We > have two objectives for this work, which could be satisfied by two > individual consultants but more likely by one: > > (1) This objective involves completing the implementation of automated > compilation of C code into DLLs. These DLLs are dynamically created > from a user's specification in python. The DLLs can be updated and > reloaded if the user changes specifications at the python level. This > functionality is crucial to providing fast solving of differential > equations using legacy solvers written in C and Fortran. This > functionality is relatively independent from the inner workings of our > project so there should be minimal overhead to completing this task. > We need to complete the integration of an existing code idea for this > objective with the main trunk of our project. The existing code works > as a stand-alone test for our C legacy solver but is not completed for > our Fortran legacy solver (so that numpy's distutils needs to be used > instead of python distutils) and needs to be integrated into the > current SVN trunk. The design document and implementation for the C > solver should be a helpful template for the Fortran solver. > > (2) We need a setup.py package installer for our project that > automatically compiles the static parts of the legacy differential > equation solvers during installation according to the directory > structure and SWIG/distutils implementation to be completed in > objective (1). If the consultant is experienced with writing python > package installers, he/she may wish to negotiate working on a more > advanced system such as an egg installer. > > PyDSTool (pydstool.sourceforge.net) is a multi-platform, open-source > environment offering a range of library tools and utilities for > research in dynamical systems modeling for scientists and engineers. > > Please contact Dr. Rob Clewley (rclewley) at (@) the Department of > Mathematics, Georgia State University (gsu.edu) for more information. > > -- > Robert H. Clewley, Ph.D. > Assistant Professor > Department of Mathematics and Statistics > and Neuroscience Institute > Georgia State University > 720 COE, 30 Pryor St > Atlanta, GA 30303, USA > > tel: 404-413-6420 fax: > 404-413-6403http://www2.gsu.edu/~matrhchttp://brainsbehavior.gsu.edu/ The SIMPL toolkit (http://www.icanprogram.com/simpl) might be able to act as a bridge to those legacy systems more readily than via the SWIG route. If you contact me directly, I could put you in touch with our best Python-SIMPL developers. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG, c++ to Python: array of pointers (double pointer) not working
On Mar 14, 5:22 am, Matteo wrote: > Re-posting in more simple and precise terms from a previous > threadhttp://groups.google.it/group/comp.lang.python/browse_thread/thread/6... > > Problem: > SWIG doesn't properly wrap c++ arrays of pointers, therefore when you > try to call a c++ function which requires them, a TypeError exception > is raised. > > Similar story here:http://osdir.com/ml/programming.swig/2003-02/msg00064.html > > Already tried: > - some ctypes functions > - tuple or string instead of list > > Possibile solutions: > something > likehttp://embedded.eecs.berkeley.edu/Alumni/pinhong/scriptEDA/pyTypemapF... > that didn't work either, but I think I was not able to adapt the code > to my case, since the example is poorly explained. > > Code to reproduce error: > I made a dptest.cpp function that calculates the sum of an array of > pointers to ints. > > #include "dptest.h" > //the header file is just > //int sum(int**, int); > > int sum(int** dp, int len){ > int sum = 0; > for (int i = 0; i < len; i++){ > sum += *(dp[i]); > } > return sum; > > } > > swig -c++ -python, then setup.py build_ext --inplace gets it nicely > compiled and wrapped for python use. It also is imported without > problems, but then... > > mat...@matteo:~/lab/sandbox$ python > Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> > import dptest as dp > >>> l = [1, 2, 3, 4] > >>> size = len(l) > >>> dp.sum(l,size) > > Traceback (most recent call last): > File "", line 1, in > TypeError: in method 'sum', argument 1 of type 'int **' > > NOTE: A pure c++ program works as expected: > > #include > > int sum(int**, int); > > int main(){ > int **array_of_ptr = new int*[4]; > for (int i = 0; i < 4; i++){ > array_of_ptr[i] = new int; > *array_of_ptr[i] = i+1; //fill it with 1,2,3,4: 1+2+3+4 = 10 > } > std::cout << sum(array_of_ptr, 4) << std::endl; > > } > > int sum(int** dp, int len){ > int sum = 0; > for (int i = 0; i < len; i++){ > sum += *(dp[i]); > } > return sum; > > } > > compiling and running prints the correct result: > mat...@matteo:~/lab/sandbox$ ./purecpp > 10 Depending on what you are wanting to accomplish with your SWIG library you may be able to more easily glue your Python code to the C++ piece using SIMPL (http://www.icanprogram.com/simpl).SIMPL is an ultra lightweight toolkit useful for gluing modules written in different languages (C, C++, Python, Tcl/Tk, JAVA) using Send/Receive/Reply messaging first pioneered by QNX. If you think SIMPL might help, don't hesitate to contact me offlist at this email address. bob SIMPL project coordinator -- http://mail.python.org/mailman/listinfo/python-list
openNetcam open source project recruiting developers
A new open source project has been started with the aim of building an open Linux framework for TCP/IP enabled video camera systems. http://www.openNetcam.net The framework will be layered on the ultra lightweight SIMPL toolkit (http://www.icanprogram.com/simpl) and when the framework is complete it will be a kind webservices lite taylored to camera systems. The target webserver is the lighttpd. There will be opportunities for openNetcam developers to create a mod-simpl plugin for that technology. Most of the systems will be deployed in an embedded Linux appliance. This will restrict the choice of programming languages for the target code somewhat. SIMPL supports C, C++, Python, Tcl/ Tk and JAVA. Of those C and C++ are probably the most embedded friendly. However, there will be lots of other aspects of the this project where Python could play a significant role. eg. test stubs. If this sort of project interests you (or if you know of anyone who might be interested) please don't hesitate to contact me offlist. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: named pipe and Linux
On Apr 7, 1:08 pm, akineko wrote: > Hello everyone, > > I'm trying to use named pipes to fuse a Python program and a C > program. > One side creates pipes using os.mkfifo() and both sides use the same > named pipes (one side reads, another side writes). The read side uses > select.select() to wait for incoming messages and read the message > when select.select() says it is ready. > > The length of the message is unknown to the read side. > I cannot use file.read() because it will block waiting for an EOF. > I cannot use file.readline() because how many lines have arrived is > unknown. > So, I needed to use os.read() with the exact number of characters to > read. > > Under Solaris environment, os.fstat() provides the exact size of the > message that has arrived. > Thus, two processes can communicate each other through the named pipes > without blocking. > > However, the above scheme didn't work under Linux. > Linux os.fstat() returns size=0 even the message is pending. > (I think Linux buffers the message in memory while Solaris buffers the > message in a file system) > > My question is, how can I make the named pipe scheme work under Linux? > Is there any way to read the message without getting blocked? > > I know this is more Linux question than Python question but I believe > many Python programmers are strong Linux programmers. > > Any suggestions will be appreciated. > > Best regards, > Aki Niimura The SIMPL open source project (http://www.icanprogram.com/simpl) provides an ultra lightweight toolkit useful for joining Python programs to C programs using a Send/Receive/Reply mechanism first pioneered by QNX.SIMPL uses a fifo synchronized shared memory scheme for the local message pass.Through the use of generic surrogate pairs SIMPL processes can be distributed across TCP/IP or RS232 (think radio modem) networks often times without any changes or recompiles. Through the use of another type of generic surrogate a Python module running on a nonLinux OS can communicate transparently with a module running on a Linux box. A SIMPL application consists of two or more SIMPL modules collaborating in this way. SIMPL modules can be written in any number of languages including Python, C, C++, Tcl/Tk or JAVA. More importantly SIMPL modules written in different languages can be mixed in a given SIMPL application. There is a Sudoku puzzle solver example here: http://www.icanprogram.com/simplBook/simplBook.self.html bob SIMPL project facilitator -- http://mail.python.org/mailman/listinfo/python-list
Re: Programming in Python with a view to extending in C at a later date.
On Apr 20, 2:57 pm, "dug.armad...@googlemail.com" wrote: > Hi, > > Say you set out to program in Python knowing that you will be > converting parts of it into C ( or maybe C++) at a later date, but you > do not know which parts. > > Can you give any general Python structure / syntax advice that if > implemented from the start, will make this future task less painful. > In addition, advice that will make this easier for automatic tools > will be good too. > > This advice might include stuff like "avoid using Python yield > as " > > Thank you in advance, > > Douglas Actually you can have your cake and eat it too. We've used the SIMPL toolkit (http://www.icanprogram.com/simpl) and its ultra lightweight toolkit to join Python programs to those written in other languages (C,C++,Tcl/Tk or JAVA). That way you can keep the parts that Python is good at in Python and keep the parts that C or C++ are good at written in those languages and join the lot together seamlessly. SIMPL will even allow those parts to be deployed on separate network nodes often without any code change or recompile. There is an onlime tutorial/course with lots of examples at: http://www.icanprogram.com/06py/main.html bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Please help me grok: webserver > python
On Apr 21, 3:20 pm, Phillip B Oldham wrote: > I'm having trouble grok'ing how to get python talking through a > webserver. I've got a lot of experience working with nginx+php-fcgi > (via a unix socket) and I'd like to know what would be the bare > minimum to get python talking in the same way. > > Now, I've looked at modules like CherryPy but they're all a little > high level and talk via http. I'd like to know how to mimic the php > setup I'm used to; I've no specific goal other than to become > aquainted with the python environment. > > Any examples would be great! There is some example code at: http://www.icanprogram.com/06py/lesson7/lesson7.html bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Web framework for embedded system
On Apr 28, 3:43 am, Thomas Heller wrote: > I'm looking for a lightweight web-framework for an embedded system. > The system is running a realtime linux-variant on a 200 MHz ARM > processor, Python reports a performance of around 500 pystones. > > The web application will not be too fancy, no databases involved > for example, but it will need to control some simple peripherals > (some parallel in/out, some dacs) attached to the system. > > It should provide a user interface showing the current state and > allowing to manipulate it via a browser, and I will probably need > to support some rpc as well. > > Does this sound sensible at all? Any suggestions? > > Thomas You should definitely check out the SIMPL toolkit (http:// www.icanprogram.com/simpl). We have used this ultra lightweight toolkit in several embedded Linux projects. It will allow you to seamlessly connect your Python bits with bits more appropriately written in other languages like C. There is a "hello world" level tutorial on the Python-SIMPL capabilities (which includes a web CGI interface) at: http://www.icanprogram.com/06py/main.html If you have any questions about our SIMPL experiences don't hesitate to ask. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Seach for encrypted socket wrapper
On Jun 2, 5:28 am, Hans Müller wrote: > Hello experts, > > I'm looking for secure way to pass messages from a python program to a > c-library in both ways. > > This scenario is given: > > display client Calculation module in > COBOL (yes, big, old but it works well) > (python, wxpython) <- Network connection -> C-Lib beeing called from > COBOL to communicaty with > display client > > The network connection should be encrypted. And fail save. > Has someone an idea what to use ? > > I have had a short look on xml rpc which can run over a https server but this > seems quite fat. > Better ideas ?! > Importand is also that the C-Lib on the cobol side should be coded as simple > as possible. > Platforms: Windows, *ix > > Thanks a lot. > > Hans The SIMPL toolkit is quite lightweight (http://www.icanprogram.com/ simpl). It can be used to join a Python program to a C program. However, SIMPL messages are treated as blocks of bytes from the prespective of the toolkit.It should be quite straightforward to graft an encription layer above this to do what you want. If you want some "hello world" level Python-SIMPL examples you can look here: http://www.icanprogram.com/06py/main.html bob -- http://mail.python.org/mailman/listinfo/python-list
Re: adding python engine into c++ application
On Dec 29 2009, 6:25 am, griwes wrote: > Hello, I am going to write an application in C++, application which > should be easy to extend by scripts. I chose python for script > language in this application. I'd like to have own API for python. And > here the question arises: how do I implement a python engine within an > application written in C++? > > Sory for any mistakes, english isn't my native language ;) If you want to keep your C++ and Python as separate but interacting modules you might want to check out the SIMPL project's (http:// www.icanprogram.com/SIMPL) Python hooks. There is some tutorial level code here: http://www.icanprogram.com/06py/main.html bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Using jython to call python procedures/methods
On Jan 20, 10:32 am, KB wrote: > Hi there, > > I have an application that only publishes a Java API. I can use jython > to access java classes, but jython currently (to the best of my > knowledge) does not support numpy/scipy. > > Ideally I would like to have jython call a "native" python routine > where I have the numpy/scipy procedures already written. > > Does anyone have any experience with this? Is it possible? > > I had toyed with the idea of having jython/java write the data to a > file/database and then manually kick off the python process, but > ideally I would like this as automated as possible. > > Thanks in advance. You might want to take a look at the SIMPL toolkit (http:// www.icanprogram.com/simpl). It sports both JAVA and Python hooks so you should be able to pump the data from your JAVA module to a Python/ numpy/scipy module. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: simple pub/sub
On Jan 21, 11:54 am, Steve Howell wrote: > Hi, I'm looking for ideas on building a simple architecture that > allows a bunch of independent Python processes to exchange data using > files and perform calculations. > > One Python program would be collecting data from boat instruments on a > serial port, then writing that info out to a file, and also > transmitting data to instruments as needed (again through the serial > port). It would be the most complex program in terms of having to > poll file descriptors, or something similar, but I want to limit its > job to pure communication handling. > > Then, I would have a bunch of programs doing various calculations on > the input stream. It's totally acceptable if they just sleep a bit, > wake up, see if there is any new data, and if so, do some > calculations, so I will probably just use this: > > http://www.dabeaz.com/generators/follow.py > > Some of the "calculator" programs might be looking for trends in the > data, and when a certain threshold is reached, they will need to > notify the comm program of the new message. To avoid collisions > between all the different calculator programs, I am thinking the > simplest thing is just have them each write to their own output file. > > So then the comm program has multiple data sources. It wants to track > to the serial port, but it also wants to monitor the output files from > the various calculator processes. I want to do this in a mostly > nonblocking way, so I would probably poll on the file descriptors. > > The only problems are that select "...cannot be used on regular files > to determine whether a file has grown since it was last read," and it > only works on Unix for files. (I'm using Unix myself, but one of the > other programmers insists on Windows, and is resisting Python as > well.) > > So a variation would be that the calculator programs talk to the comm > program via sockets, which seems slightly on the heavy side, but it is > certainly feasible. > > I know that something like twisted could probably solve my problem, > but I'm also wondering if there is some solution that is a little more > lightweight and batteries-included. > > At the heart of the matter, I just want the programs to be able to do > the following tasks. > > 1) All programs will occasionally need to write a line of text to > some data stream without having to lock it. (I don't care if the > write blocks.) > 2) All programs will need to be able to do a non-blocking read of a > line of text from a data stream. (And there may be multiple > consumers.) > 3) The comm program will need to be able to poll the serial port and > input data streams to see which ones are ready. > > Any thoughts? You should definitely check out the SIMPL toolkit (http:// www.icanprogram.com/simpl). It has some pretty mature Python hooks. SIMPL has been used to construct data acquisition applications not unlike the one you describe. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Python & OpenOffice Spreadsheets
On Nov 23, 5:49 am, Gerhard Häring wrote: > Is there a *simple* way to read OpenOffice spreadsheets? > > Bonus: write them, too? > > I mean something like: > > doc.cells[0][0] = "foo" > doc.save("xyz.ods") > > >From a quick look, pyodf offers little more than just using a XML parser > > directly. > > -- Gerhard OO Calc has an HTML file feature for auto updating fields in a spreadsheet. I hacked together something for a talk a few years ago: http://www.icanprogram.com/hosug (See Open Office Calc demo section) While it isn't Python code it should be easy enough to convert to Python. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: simple and fast platform independent IPC
On Feb 3, 3:32 am, News123 wrote: > Hi, > > I wondered what IPC library might be best simplest for following task? > > I'm having a few python scripts all running on the same host (linux or > win), which are started manually in random order. (no common parent process) > Each process might be identified by an integer (1,2,3) or by a symbolic > name ( 'dad' , 'mom' , 'dog' ) > > these scripts want to send short messages to each other ( mostly > integers, max a few bytes, short string), which would be enqueued in > message queues of the receiving process. > > example: > > 'dad' wants to tell 'mom': 'cook' > 'dog' wants to tell 'dad' : 'feedme' > 'mom' wants to tell 'dad' : 'cookyourself' > > the receiver dos not necesarily have to know who sent the message > > a message shall be dropped silently if the receiving process is not running > > a message shall be reliably delivered if the receiving process is up > > xmlrpc seems to be a little heavy for such tasks. > > signals don't allow to exchange data > > a shared memory message queue would probably a good solution, but > python's Multiprocessing.Queue seems to require a common parent process > > thanks a lot for any ideas / suggestions > > N > > N Have a look at the SIMPL toolkit (http://www.icanprogram.com/simpl or http://www.icanprogram.com/06py/main.html). It should do everything you describe at least on the Linux end of the spectrum. Under the hood SIMPL uses a shared memory scheme for local message exchange. SIMPL would be especially effective if you want to move your modules at some future point onto different nodes. SIMPL-Python can work seamlessly on heterogeneous networks provided at least one node is Linux. bob -- http://mail.python.org/mailman/listinfo/python-list
strange issue with C extension using Py_BuildValue
I'm am having "strange" problems with the code snip below. When this code is built on a 64bit Linux, it would appear to work flawlessly.When the source is rebuilt on a 32bit Linux it begins to crack in strange ways. The issue seems to be associated with the sender field in the Py_BuildValue call.The fact that sender is a pointer should mean that its value is an unsigned integer.However, on the 32 bit build the failure is that the msgPtr->data value is "messed up". If the format associated with the sender (a pointer) from "L" to "i" things work on the 32 bit side but break on the 64 bit side. I fully understand that an address will be stored differently on the 64bit vs. the 32bit systems. The problem is that the code is recompiled from source in both cases so shouldn't the "L" format work as expected in both architectures?Furthermore, how can an incorrect format result in messing up the field which follows? Thanks in advance for any help. bob PS. The Python side using this extension isn't expecting to do anything with the sender parameter other than store it for later use as a parameter in a Reply() function call. ie. an address goes from extension ->Python -> extension. = begin code snip === static PyObject *simpl_receive(PyObject *self, PyObject *args) { int ret; char *sender; FCMSG_REC *msgPtr; // call the actual simpl C library function ret = Receive(&sender, NULL, 0); // what sort of message are we dealing with? if (ret > 0) // message { msgPtr = (FCMSG_REC *)sender; return( Py_BuildValue("iLz#", ret, sender, &msgPtr->data, ret) ); } == end code snip -- http://mail.python.org/mailman/listinfo/python-list
ANN: Python-SIMPL v2.0.0 released
The SIMPL project (http://www.icanprogram.com/simpl) aims to bring the Send/Receive/Reply messaging (first popularized by QNX) to the open source Linux world. Since its inception more that 10 years ago, the SIMPL toolkit has grown steadily in functionality. Through the use of surrogates, SIMPL modules can be dispersed seamlessly across networks including heterogeneous networks with only one Linux node. SIMPL modules can also be written in several programming languages including Python, C, C++, JAVA and Tcl/Tk. Modules written in different languages can be mixed in a SIMPL appliction. Python-SIMPL has been used to connect Python UIs to C data acquisition/ computation backends. While this is an example of a common use for the toolkit, it is by no means the only place it could be useful. Python to Python, Python to JAVA as well as Python to C are all seamlessly possible in both local or distributed applications. Python- SIMPL allows a software application to be broken up into modules where the language choices for each module can be optimized. The Python-SIMPL interface library has undergone a fundamental revision with the v2.0.0 release. The underlying shared library which wraps the SIMPL toolkit as a Python extension was cleaned up considerably. In addition two new Python wrappers were created to expose this SIMPL toolkit in more object oriented fashion to the Python developer. The simplest starting point for exploring the Python-SIMPL toolkit is an online "hello world" level tutorial at: http://www.icanprogram.com/06py/lesson1/lesson1.html The Python-SIMPL toolkit can be downloaded in source form at: http://www.icanprogram.com/simpl/python.self.htm or in precompiled binary (i386) form at: http://www.icanprogram.com/simpl/pythonbin.self.html We at the SIMPL project welcome participants at all levels of expertise. If you are interested do not hesitate to contact us. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python-SIMPL v2.0.0 released
On Feb 22, 9:40 am, bobicanprogram wrote: > The SIMPL project (http://www.icanprogram.com/simpl) aims to bring the > Send/Receive/Reply messaging (first popularized by QNX) to the open > source Linux world. Since its inception more that 10 years ago, the > SIMPL toolkit has grown steadily in functionality. Through the use > of surrogates, SIMPL modules can be dispersed seamlessly across > networks including heterogeneous networks with only one Linux node. > SIMPL modules can also be written in several programming languages > including Python, C, C++, JAVA and Tcl/Tk. Modules written in > different languages can be mixed in a SIMPL appliction. > > Python-SIMPL has been used to connect Python UIs to C data acquisition/ > computation backends. While this is an example of a common use for > the toolkit, it is by no means the only place it could be useful. > Python to Python, Python to JAVA as well as Python to C are all > seamlessly possible in both local or distributed applications. Python- > SIMPL allows a software application to be broken up into modules where > the language choices for each module can be optimized. > > The Python-SIMPL interface library has undergone a fundamental > revision with the v2.0.0 release. The underlying shared library which > wraps the SIMPL toolkit as a Python extension was cleaned up > considerably. In addition two new Python wrappers were created to > expose this SIMPL toolkit in more object oriented fashion to the > Python developer. > > The simplest starting point for exploring the Python-SIMPL toolkit is > an online "hello world" level tutorial at: > > http://www.icanprogram.com/06py/lesson1/lesson1.html > > The Python-SIMPL toolkit can be downloaded in source form at: > > http://www.icanprogram.com/simpl/python.self.htm > > or in precompiled binary (i386) form at: > > http://www.icanprogram.com/simpl/pythonbin.self.html > > We at the SIMPL project welcome participants at all levels of > expertise. If you are interested do not hesitate to contact us. > > bob There is a typo in the source link. It should read http://www.icanprogram.com/simpl/python.self.html Sorry about that. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Ideas for creating processes
On Mar 10, 4:52 pm, J wrote: > I'm working on a project and thought I'd ask for a suggestion on how > to proceed (I've got my own ideas, but I wanted to see if I was on the > right track) > > For now, I've got this: > > def main(): > ## get our list of directories to refresh > releases=sys.argv[1:] > if len(releases) < 1: > print "You need to provide at least one dir to update" > sys.exit() > > ## Lets figure out what there is to update > updateDirs = [] > for rel in releases: > currentDir = os.path.join(homedir, rel) > for item in os.listdir(currentDir): > updateDirs += [os.path.join(homedir, rel, item)] > > which returns a list of full pathnames to directories that need to be > updated (updates will be carried out by calling rsync or zsync > eventually) > > The directory hierarchy looks like this: > > /home/user/files > /home/user/files/version1 > /home/user/files/version1/type1 > /home/user/files/version1/type2 > /home/user/files/version2 > /home/user/files/version2/type1 > > and the list ends up looking like this: > > ['/home/user/files/version1/type1','/home/user/files/version1/type2','/home/user/files/version2/type1','/home/user/files/version2/type2'] > > the next thing I need to do is figure out how to update those. > > the quick and dirty would be (as I'm imagining it at the moment): > for path in pathlist: > chdir into path > execute rsync or zsync > > but that gets me moving into one dir, updating, then moving into another. > > What I was wondering about though, is spawning off separate rsync > processes to run concurrently (each rsync will hit a different remote > dir for each local dir) > > so I'm trying to figure out a good way to do this: > > for path in pathlist: > kick off an individual rsync|zsync process to update path > > wait for all child processes to end > exit program. > > I've been looking at subprocess because at the moment, that's all I > really know... > But is there a better way of kicking off multiple simultaneous > processes so I can update all dirs at once instead of one at a time? > > No, this isn't homework, it's something I'm working on to sync a > couple directories of ISO images to grab nightly builds > Yes, there are plenty of pre-made scripts out there, but I don't want > to even look at those because I figured this would be a good learning > experience, and I want to try to solve this as much on my own as I can > without just cut and pasting from someone elses program. > > So, with that said, any ideas on the best way to proceed? I'm going > to start looking at ways to use subprocess to do this, or would there > be a better way (multi-threading maybe?) > > Or am I even in the right ballpark? > > Cheers > Jeff You might be able to use the SIMPL toolkit for this one. (http://www.icanprogram.com/06py/lesson1/lesson1.html) You could wrap the rsync executable as a SIMPL receiver module and then message to that from inside your Python script to kick it off and synchronize actions. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Advice needed on parallel processing in python
On Mar 24, 1:13 pm, Jon Clements wrote: > On 24 Mar, 15:27, Glazner wrote: > > > > > Hi! > > > I need to replace an app that does number crunching over a local > > network. > > it have about 50 computers as slaves > > each computer needs to run COM that will do the "job" > > right now the system uses MFC threads and DCOM to distribute the load. > > > as i said, Now i'm trying to replace this system with python. > > I already use win32all and read about Pareller Python and Pyro. > > > a requirement is that messages can be sent to the remote worker. > > > If anyone can share experience I'll love to hear > > > Many Thanks, > > Yoav Glazner > > Would Celery suit?http://celeryproject.org/ > > hth > > Jon. If you can add just one Linux server onto that network you could use SIMPL-Python to do what you want. http://www.icanprogram.com/06py/lesson1/lesson1.html ie. SIMPL messages going seamlessly from Python (Windows) to Python (Windows) with the SIMPL sandbox being hosted on the Linux node. Of course if you wanted to add Linux nodes as processing nodes. Python (Windows) modules could seamlessly exchange messages with those as well. Same would be true if you wanted to distribute part of your app into the cloud. All your Python code would look virtually identical in each of these cases. As an example of an inexpensive Linux node the SIMPL toolkit has been ported to the ~$100 Sheeva Plug computer (http://www.icanprogram.com/ simpl/plugsimplbin.self.html) (http://www.plugcomputer.org). bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is cool!!
On Mar 23, 11:55 am, Jose Manuel wrote: > I have been learning Python, and it is amazing I am using the > tutorial that comes with the official distribution. > > At the end my goal is to develop applied mathematic in engineering > applications to be published on the Web, specially on app. oriented to > simulations and control systems, I was about to start learning Java > but I found Python which seems easier to learn that Java. > > Would it be easy to integrate Python in Web pages with HTML? I have > read many info on Internet saying it is, and I hope so > > Any opinion You probably want to take a look at this tutorial as well: http://www.icanprogram.com/06py/lesson1/lesson1.html The SIMPL toolkit will give you added flexibility to choose the language for some of your more computationally intensive simulations and still present a unified Python interface to the whole thing. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Python + OpenOffice Calc
On Mar 31, 2:47 am, Tracubik wrote: > Hi all! > i'm giving away to a friend of mine that have a garage (he repair car) my > old computer. He will use it essentialy to create estimates of the work > via an ods file (i've made a simple ods file to be filled with the cost of > materials and a description of the work). > He's totally new with computer and have difficult to fill the ods file, so > i'ld like to create a simple python program that help him to introduce the > data in to the ods file via a simple gui. > So what i'm looking for is a way in python to insert data in a particular > cell of the ods file and possibly to save it and print it when it's full > filled with data. > > the guy is similar to this: > > 3 fields: quantity - description of the piece bought - price > > a way to add a new "line" if needed (for a new piece entry) similar to the > "add rule" in evolution > > 1 text field for the description of the work + 1 field for the price of > the work > > and off course a way to insert this data in to the ods file via python > > Any hints/tutorial/info? > > thanks > Nico OOcalc supports a little known feature whereby data can be automatically sync'd between the spreadsheet and an HTML table. A few years ago I did up a demo of this in action using Tcl/Tk (http:// www.icanprogram.com/hosug). It should not be too hard to port this idea to Python. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Round Trip: C to Python to C Module
On Nov 19, 11:05 am, Eric Frederich wrote: > I have a proprietary software PropSoft that I need to extend. > They support extensions written in C that can link against PropLib to > interact with the system. > > I have a Python C module that wraps a couple PropLib functions that I > call PyProp.>From an interactive Python shell I can import PyProp and call a > function. > > None of these functions really do anything outside the context of > being logged into the PropSoft software; so all the functions fail > when running from Python alone. > > To my amazement, I was able to run PyRun_SimpleString("import > PyProp\nPyProp.some_function()") without setting PYTHONPATH or > anything. How this works, I don't know and I don't really care (at > the moment anyway). > > The problem I'm having now is how do I return things from my Python > script back to C? > Ultimately I won't be hard coding python inside of PyRun_SimpleString > but loading the script from a file. > So, how do I return values back to C? Python functions return values > but running a python script?... doesn't that just have an exit status? > Is there a mechanism for doing this? > > Thanks in advance, > ~Eric If you find you can't make this work as planned, you might want to check out the SIMPL toolkit (http://www.icanprogram.com/06py/lesson1/ lesson1.html) for an alternative way to connect C programs to Python modules. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Hosting a Python based TCP server
On Dec 23, 7:01 am, Oltmans wrote: > Hi all, > > I'm writing a very small TCP server(written in Python) and now I want > to host it on some ISP so that it can be accessed anywhere from the > Internet. I've never done that before so I thought I should ask for > some advice. Do you guys know any good ISP that can let me do that? > > Most importantly, what is usually involved in order to make this > happen? > > Please pardon my ignorance and I will really appreciate your reply. > Thanks in advance. If you are familiar with Linux a Linode (http://www.linode.com) might be a perfect option for you. They even offer month by month rentals. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: client server socket interaction (inetd)
On Feb 17, 2:41 pm, Martin Gregorie wrote: > On Thu, 17 Feb 2011 08:14:36 -0800, Tim wrote: > > Hi, I have an inetd service on freebsd that calls a program (daemon.py) > > with which I want the remote user to communicate. I can call daemon.py > > from the command line on the host machine and it works fine. > > > What I don't understand is how to make my remote client script actually > > communicate. If I'm understanding correctly, the code below just takes a > > message and sends it to inetd and writes the stdout from the process to > > the client. > > > How can I modify the code to send a response back? > > The code you've shown would appear to be doing what you've specified, > though only you can know whether this is what you intended. > Each time you run the client it: > - connects to the server > - sends a request > - reads the response(s) > - closes the socket and exits. > > If you run it a second time it should do the same again. Is this the case? > > An inetd server should be started when a connection request is received. > It should read requests, sending a response to each request in turn, > until the connection is closed, when it will be stopped by inetd. > > Without seeing the code for the server and the corresponding inetd > configuration line its not possible to say more. > > BTW, I prefer xinetd to inetd - its configuration is much more modular > and easier to understand. If freebsd supports xinetd it may make life > easier if you use it rather than inetd. > >Here's the outline > > > > > of what I want to do: > > (1) client sends the message to the server (client -> inetd -> > > daemon.py), > > (2) client receives output back from the server, (3) client user > > responds to a question from the remote process (4) client continues to > > receive output back. > > > where 2-3-4 happen as needed by the remote process. Cries out for a > > while loop doesn't it? I just don't know what to put in it. Currently I > > just have steps 1 and 2 working. Client sends one message and gets all > > output back. If server asks a question, processes deadlock with server > > waiting and client unable to respond. thanks, > > --Tim Arnold > > > # imports, constants set > > #def line_buffer(sock): > > #code to yield the string response in #blocks of 1024 bytes > > > def client(ip,port,message): > > sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) > > sock.connect((ip,port)) > > sock.send(message) > > for line in line_buffer(sock): > > print line > > sock.close() > > > if __name__ == '__main__': > > message = ' '.join(sys.argv[1:])) > > print 'working... %s %s' % (SERVER_IP,SERVER_PORT) > > client(SERVER_IP,SERVER_PORT,message) print 'done.' > > -- > martin@ | Martin Gregorie > gregorie. | Essex, UK > org | Have a look at the SIMPL toolkit (http://www.icanprogram.com/06py/ lesson1/lesson1.html). It will allow you to do exactly what you want without having to dive into socket programming. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: speed up a numpy code with huge array
On May 26, 7:43 am, Alexzive wrote: > thank you all for the tips. > I 'll try them soon. > > I also notice another bottleneck, when python tries to access some > array data stored in the odb files (---> in text below), even before > starting the algoritm: > > ### > EPS_nodes = range(len(frames)) > for f in frames: > ... sum = 0 > --->UN = F[f].fieldOutputs['U'].getSubset(region=TOP).values <--- > ... EPS_nodes[f] = UN[10].data[Scomp-1]/L3 > > ### > > unfortunately I don't have time to learn cython. Using dictionaries > sounds promising. > Thanks! > Alex > > On May 26, 8:14 am, Stefan Behnel wrote: > > > Alexzive, 25.05.2010 21:05: > > > > is there a way to improve the performance of the attached code ? it > > > takes about 5 h on a dual-core (using only one core) when len(V) > > > ~1MIL. V is an array which is supposed to store all the volumes of > > > tetrahedral elements of a grid whose coord. are stored in NN (accessed > > > trough the list of tetraelements --> EL) > > > Consider using Cython for your algorithm. It has direct support for NumPy > > arrays and translates to fast C code. > > > Stefan The SIMPL toolkit (http://www.icanprogram.com/06py/lesson1/ lesson1.html) might be a simpler way to offload some processing to faster C code. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Returning value from home made unit - how to?
On May 30, 6:22 pm, Mel wrote: > Martin Hvidberg wrote: > > I have a Python program, which has until now, been running in command line > > mode only. I wish to add a GUI. > > > I would like to develop (and maintain) the GUI part in a separate module, > > i.e. in its own .py file, and then ‘import’ that into the old main > > program. > > > I jumped into wxPython, as it seems to be the right GUI for me, and > > downloaded some examples that I took apart and joined. Now the basic GUI > > is running, though neither beautiful nor complete. > > > The main task for my GUI is to allow the user to point to an input file. > > It can now obtain a filename from a file selection dialog, but I can’t > > figure out how to get the filename, i.e. the string variable containing > > the file name, send back to the main program… > > > I attach the two .py files hereunder. > > > My question is: > > How do I get the information from variable strSequenceFile, back to the > > main module in file jacxl.py ? > > AFAIK, typically, you don't -- the way it is here. Returning a value from a > Button handler, or any event handler generally, won't have any effect. The > event handlers are called from deep in wx code by routines that don't deal > with anything specific to the data-processing side of the program. > > What I think you might do is to make strSequenceFile an attribute of your > Frame, so that OnFindFile button does ``self.strSequenceFile = > dialog.GetPath()'' rather than returning that value. > > Then your main level can do ``jacXlgui.app.GetTopWindow().strSequenceFile'' > . > > There are probably refinements to be added to this, but I think it's a good > beginning strategy. The first new place I would take the whole program > would be to remove the command-line controls from the command line program, > so you're left with a sort of "business model" that contains only the data > processing. Then you can write a new GUI program based on jacXlgui that > imports the data processing module and calls computations and reports > results from the model. > > Mel. Another way to encapsulate functionality like a GUI is to "hide" it behind a nice clean messaging interface. The SIMPL toolkit (http:// www.icanprogram.com/06py/lesson1/lesson1.html) promotes this kind of design. SIMPL allows Python to Python messaging as well as Python to C, C++, JAVA or Tcl/Tk so what you ultimately choose for the GUI has only minimal impact on what you choose for your "processing engine". Happy coding. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Python GUI for C program [was: ]
On Jul 6, 7:45 am, Thomas Jollans wrote: > On 07/06/2010 12:15 PM, francisco dorset wrote: > > > hey am a programmer i have good knowledge of the c language and i will > > like to now how i can use to python to provide graphical user-interface > > for my c programs and or the steps involved in doing this and is it > > possible > > > if yes i will also like some resources or books to learn from. > > > any info will be useful thankss > > Three ways of doing this: > > 1. Turn your C program into a library, and write a Python extension >module to interface it. > > 2. Embed Python in your C program. > > 3. If you're talking command-line programs, you can interface the >compiled programs with the subprocess module. > > For (1) and (2), start with the Extending/Embedding section > athttp://docs.python.org/py3k/(orhttp://docs.python.org/). With (1), > using Cython or SWIG might make writing the "glue" between Python and > your C code easier. > > For (3), check the docs of the subprocess module. > > It might, however, be best to simply write the GUI in C as well, which > would avoid the overhead of loading Python and isn't all that difficult > either. If you know C++, check out wxWidgets and Qt4. To stick with > plain C, have a look at GTK+. > > Cheers, > Thomas You might want to also look at the SIMPL toolkit (http:// www.icanprogram.com/06py/lesson1/lesson1.html). You could use Send/ Receive/Reply (QNX style) messaging to add a Python GUI to a C program. There are examples of just this at the link above. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: xmlrpc and processes
On Aug 9, 2:50 am, iu2 wrote: > Hi, > > I have a SimpleXMLRPCServer running on one PC. > I need several ServerProxy-s talking to it, each one running on a > different PC. That is, I run on each PC a client application, that > talks to the one server using xml-rpc. > > Is the xml-rpc designed to work like this? If not, is there something > I can do to still be able to work with xml-rpc in this architucture? > > Thank you very much I don't have any direct experience with SimplXMLRPC, but depending on what you are actually trying to accomplish this technique might also work: http://www.icanprogram.com/06py/lesson1/lesson1.html Since SIMPL messaging is lower down on the stack than XML you could probably use SIMPL messages to carry XML structured content from client to server. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing a python script while it is running
On Jun 17, 1:42 am, Zach Hobesh wrote: > On Tue, Jun 16, 2009 at 6:37 PM, Chris Rebert wrote: > > On Tue, Jun 16, 2009 at 6:21 PM, wrote: > >> Hey Dave, > > >> Thanks for the helpful responses. > > >>> Option 2 is what you get by default. Naturally it depends on what the > >>> application is using to launch the batch file, but the most common cases > >>> will launch a separate process. > > >> The app ended up delaying starting the second batch file until it finished > >> the first. I had the app trigger an infinite loop on completion, and sent > >> two files through at the same time. The second file finished seconds after > >> the first, but the batch file didn't trigger until I closed the first one. > > > Are you sure you aren't unknowingly having the app wait on the first > > batch file process until it terminates? How exactly are you launching > > the batch files? > > > Cheers, > > Chris > > -- > >http://blog.rebertia.com > > Hey Chris, > > I actually think that's what's happening, which is fine in my case > (for now anyway) as I just need them all to complete, we don't need > them running at the same time. I'm using a job management system, and > they have the option of triggering a command line after completing a > job. > > A better/safer solution might be spawning another job and re-inserting > to the jms queue. > > Thanks again, > > Zach You might want to take a look at the Python-SIMPL toolkit (http:// www.icanprogram.com/06py/main.html). SIMPL uses a Send/Receive/Reply interprocess messaging scheme which will naturally queue requests for you. Without too much effort you may be able to reorient your scheme to eliminate the batch file entirely. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting Python code to C/C++
On Jun 23, 11:49 am, Kurt Smith wrote: > On Mon, Jun 22, 2009 at 9:49 PM, Andras > > > > Pikler wrote: > > Hi! > > > Short: I need to turn a Python program that I (mostly) wrote into C code, > > and I am at a loss. > > > Long: I’m doing research/programming for a professor, and we are working > > with MIDI files (a type of simple music file). The research deals with > > generating variations from a musical melody; currently, my Python code uses > > a Python midi package I found online to read the notes in question from a > > midi file, about 350 lines of my own code to generate a variation based on > > these notes and the professor’s algorithms, and finally the package again to > > write the new melody to another midi file. > > > Now, my professor would like to have this exact code in C/C++, as she > > believes C is more compatible with MATLAB, and wants the code to be > > available in multiple languages in case a programmer works for her in the > > future who knows C but not Python. While I know a tiny bit of C (emphasis on > > the tiny), I would much prefer if there were some sort of automatic compiler > > I could use to turn my Python code into C than taking a week or two or three > > to learn the minimum I need about C, find a way to access MIDI files in it, > > and rewrite all of my code. > > > After some googling, I found and tried Shedskin, but it doesn’t work, as the > > Python midi package I’m using uses modules which Shedskin does not support. > > Otherwise, I haven’t found much. Is there anything out there to help me do > > this? If not, from anyone who has experience in this regard, how daunting > > should I expect this to be? > > Taking on C from a cold start and being able to handle the ins and > outs of interfacing with Python isn't something that's feasible in > 'two or three weeks'. Here are a couple of options -- take 'em or > leave 'em: > > 1) Put the code in Cython:http://www.cython.org/ (full disclosure: > I'm doing a GSoC project with Cython). It will convert pretty much > any python code into C code (even closures are supported in the most > recent version, I think), and the C code can then be compiled into an > extension module. > > The only problem with the above is the C code isn't, at first blush, > easy to read. Nor is it supposed to be changed by the user. So that > leads us to option... > > 2) Write the core functionality in C yourself, and then wrap those C > functions in Cython. You'll want to take a look at the documentation: > > http://docs.cython.org/ > > and, more specifically on wrapping C code: > > http://docs.cython.org/docs/external_C_code.html > > I don't think you'll be able to avoid learning C, though. > > Kurt 3) use Python-SIMPL to connect your C module to your Python module using a 5 function API without any need for wrappers. ie. have your cake and eat it too http://www.icanprogram.com/06py/main.html bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters for a C program in Linux.
On Jun 30, 6:46 am, "venutaurus...@gmail.com" wrote: > Hi all, >I have to write an automted script which will test my c > program. That program when run will ask for the commands. For example: > > local-host# ./cli > Enter 1 for add > Enter 2 for sub > Enter 3 for mul > 1---Our option > Enter two numbers > 44 33 Our option > Result is 77 > > As shown in the above example it lists all the options and waits for > user input and once given, it does some operations and waits for some > more. This has to be automated. > > Can someone give suggestions how to do this in Python (Linux Platform > in particular). > > Thank you, > Venu. Take a look at the examples here: http://www.icanprogram.com/06py/main.html You can probably do what you want using the SIMPL toolkit quite easily. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing handlers between bound c++ libs
On Jul 14, 7:07 pm, Freyr wrote: > I have a python bound physics library that uses handler to process > events. The passing of handlers between c++ and python causes a huge > overhead slowing down the process. Can I implement a handler in my > custom python bound c++ lib B and pass it to blackbox python bound c++ > lib A so that A would call B directly without passing through the > python layer? Or to phrase the question differently: Can I pass a > handler from B through python to A so that A will invoke B with out > calling into python code? Depending on your exact configuration you may be able to wrap that C++ library using the SIMPL toolkit and get at your data with a message.There is some "hello world" demo code here: http://www.icanprogram.com/06py/main.html bob -- http://mail.python.org/mailman/listinfo/python-list
Re: basic 2 player wordgame
On Sep 21, 6:25 am, Baba wrote: > Hi > > I am working on a simple wordgame exercise: 2 players form a word by > alternating turns saying a letter, which is added on to the end of the > word fragment. > > I am familiar with loops, iterations etc but i need a hint as to how > to approach alternating turns when writing this code? > > exercise > source:http://ocw.mit.edu/courses/electrical-engineering-and-computer-scienc... > > thanks > Baba Have a look at the SIMPL toolkit (http://www.icanprogram.com/06py/ lesson1/lesson1.html). This would allow your two players to be split into two separate Python modules. It has the "advantage" that once completed those two players could be deployed across a network, likely without any code changes. bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross compiling (i386 from amd64) with distutils
On Nov 7, 7:19 pm, Jason wrote: > My situation is this: I have a Diamond Systems single-board computer > with a > matching GPIO board. DS have a library for controlling the GPIO > board... but > it's a static library (libdscud-6.02.a) with an accompanying header > (dscud.h). > I'd like to create a Python extension to use the device. > > The architecture of the SBC is 486, and it runs Debian Squeeze/Grip. > While it > is possible to develop on it directly, I'd rather use my desktop > machine > (Debian Squeeze, amd64). > > If I write a simple C program to control the device, I'd include the > header > file and cross-compile it like so: > > gcc -m32 -march=i386 -lpthread -I/usr/local/dscud-6.02 -o dio > dio.c \ > /usr/local/dscud-6.02/libdscud-6.02.a > > To get myself started with the Python extension, I've basically taken > the > "noddy" demo[1] and thrown in a function call from the DSC library > just to see > if I can get something to build. > > My distutils setup.py looks like: > > > from distutils.core import setup, Extension > > module1 = Extension('noddy', > sources = ['src/noddy.c'], > libraries = ['pthread'], > include_dirs = ['/usr/local/dscud-6.02'], > extra_objects = ['/usr/local/dscud-6.02/libdscud-6.02.a'], > extra_compile_args = ['-m32', '-march=i386']) > > setup(name = 'Noddy', version = '1.0', description = 'This is a demo > package', > ext_modules = [module1]) > > > This works fine on the target machine with "python setup.py build", > but when I > try it on my desktop machine, I get: > > > $ python setup.py build > running build > running build_ext > building 'noddy' extension > creating build > creating build/temp.linux-x86_64-2.6 > creating build/temp.linux-x86_64-2.6/src > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall > -Wstrict-prototypes -fPIC -I/usr/local/dscud-6.02 -I/usr/include/ > python2.6 -c > src/noddy.c -o build/temp.linux-x86_64-2.6/src/noddy.o -m32 - > march=i386 > In file included from /usr/include/python2.6/Python.h:58, > from src/noddy.c:1: > /usr/include/python2.6/pyport.h:694:2: error: #error "LONG_BIT > definition > appears wrong for platform (bad gcc/glibc config?)." > error: command 'gcc' failed with exit status 1 > > > > So is it possible to get distutils to cross compile something like > this, and > if so, what am I missing? Or am I using the wrong tool for the job? > > Target python ver. is 2.6. GCC is 4.4.5. > > Cheers, > Jason > > [1]http://docs.python.org/extending/newtypes.html Cross compilation might be one solution to Python access. The SIMPL toolkit (http://www.icanprogram.com/simpl; http://www.icanprogram.com/06py/lesson1/lesson1.html) might be easier. If you ultimately want to communicate from a 64bit to a 32bit system, you'll probably want to use a text based tokenized messaging strategy as opposed to the binary one in these examples. bob -- http://mail.python.org/mailman/listinfo/python-list