python

How to interrupt python multithreaded app?

I'm trying to run the following code (it i simplified a bit): def RunTests(self): from threading import Thread import signal global keep_running keep_running = True signal.signal( signal.SIGINT, stop_running ) for i in range(0, NumThreads): thread = Thread(target = foo) ...

Reduce left and right margins in matplotlib plot

I'm struggling to deal with my plot margins in matplotlib. I've used the code below to produce my chart: plt.imshow(g) c = plt.colorbar() c.set_label("Number of Slabs") plt.savefig("OutputToUse.png") However, I get an output figure with lots of white space on either side of the plot. I've searched google and read the matplotlib docume...

How to run libvirt on jython 2.5.1?

Does anyone know this? ncm-xen1:/usr/lib64/python2.6/site-packages # ls libvirt* libvirtmod.so libvirt.py libvirt.pyc libvirt$py.class ncm-xen1:/opt/jython2.5.1 # ./jython Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54) [Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_14 Type "help", "copyright", ...

how to make package for my python project

Hi, I have a python project, which uses qt(UI) for user input and then creates the pdf using latex. I want to make full package of my whole projects in some form of exe. I came to know about pyinstaller, pyexe and cx_frezer. So which one should I pick up first. My exe should run in windows 98, xp, vista and linux. So how does MIketex( ...

Django: If I added new tables to database, how can I query them?

Django: If I added new tables to database, how can I query them? Do I need to create the relevant models first? Or django creates it by itself? More specifically, I installed another django app, it created several database tables in database, and now I want to get some specific data from them? What are the correct approaches? Thank you...

Defining Constants in Django

I want to have some constants in a Django Projects. For example, let's say a constant called MIN_TIME_TEST. I would like to be able to access this constant in two places: from within my Python code, and from within any Templates. What's the best way to go about doing this? EDIT: To clarify, I know about Template Context Processors and...

Display help message with python argparse when script is called without any arguments

This might be a simple one. Assume I have a program that uses argparse to process command line arguments/options. The following will print the 'help' message: ./myprogram -h or: ./myprogram --help But, if I run the script without any arguments whatsoever, it doesn't do anything. What I want it to do is to display the usage message ...

Where does Python root logger store a log?

I'm using the Freebase Python library. It creates a log before executing: self.log = logging.getLogger("freebase") Where is this log in the file system? It's not in the executing directory or tmp. ...

What is __main__.py?

What is the __main__.py file for, what sort of code should I put into it and when should I have one at all? :) ...

Python equivalent to C#'s using statement

Possible Duplicate: What is the equivalent of the C# using block in IronPython? I'm writing some IronPython using some disposable .NET objects, and wondering whether there is a nice "pythonic" way of doing this. Currently I have a bunch of finally statements (and I suppose there should be checks for None in each of them too - ...

Giving my Python application a web interface to monitor it, using Tornado

I've got a Python application which is daemonized and running on a server 24/7. I'd like to be able to give an incredibly simple web interface so that I can monitor the changing values of a few variables within the program. I'm using Tornado, and I'm up and running with the simple 'Hello, world' that you can find on the Tornado homepag...

Python How to share a serial port with two different threads (Class A, Class B)

Hello guys, thank your for reading. Well, I have a single python process which is using a serial port (unique resource) which is manage using an instance of a (A=Class A). Exist two different thread initialized using B=Class_B() and C=Class_C(), which are constantly using the serial port resource through the objected already created cal...

how to implement GUI window or a frame for bash shell with wxwidget or wxpython

HI, guys. I want to develop a window or frame for the bash shell program. Even after trials with the code of the link given by Bryan (thank you so much!!), it still does not work. Basically, I use the code sample put by Anurag Uniyal. However, I have to deal with several processes (so one window for one subprocess call). I do not know ...

package data not installed from python .egg file

I'm trying to include some data files in a python package using the setuptools package_data option. I'm then accessing the files with pkg_resources. This works perfectly when the python .egg file is installed as-is (i.e. still zipped). But when the egg file is unzipped during installation, the data files are not installed. In other word...

Scons Hierarchical Builds with Repository directory.

I have an SCons project set up as follows: proj/ SConstruct src/ c/ h/ app1/SConscript app2/SConscript ... All source/header files for each application are located in src/c and src/h. At first step I created a SConstruct in app1 which use the Repository function. ... src=Split("main.c ...

Convert xml to pdf in Python

Hello everyone, I have a problem when I try to convert a XML file in a PDF file, here I’m going to explain briefly how I try to generate a PDF file. We suppose I get the information from a database, then the code source is the following: import pyodbc,time,os,shutil,types import cStringIO import ho.pisa as pisa import urllib def HTML...

HTML table with writable cells?

Hello, I've been trying to build a simple GAE app and to be able to manipulate the position of the text on the screen. I asked the same question on several forums; so far with no solution. I apologize if my question has not been clear. Now I thought of achieving the same functionality with a grid, like a spreadsheet. Do you know how I...

How to escape a % sign in a configobj value?

I'd like to use both parse time and runtime interpolation for values of a configobj configuration file. The easiest way to do simple string interpolation in Python is "%(foo)s" % somedict. Unfortunately configobj uses the same interpolation mechanism and I have not yet found a way to escape it. Ideally my value would look like: othervar...

python sockets, what's the best way to handle several connections at once ?

What's the best way to handle lots of connections at once in python? The first way I think of is threading, which works but at 10MB of RAM per thread that's rather expensive. So what other ways are there to handle lots of connections at once ? The only problem I see without using threads is that using the socket.recv() waits for data f...

What is a Hash table and how it use in Python's dictionaries?

Can anyone help me, ? ...