Q_Id
int64
337
49.3M
CreationDate
stringlengths
23
23
Users Score
int64
-42
1.15k
Other
int64
0
1
Python Basics and Environment
int64
0
1
System Administration and DevOps
int64
0
1
Tags
stringlengths
6
105
A_Id
int64
518
72.5M
AnswerCount
int64
1
64
is_accepted
bool
2 classes
Web Development
int64
0
1
GUI and Desktop Applications
int64
0
1
Answer
stringlengths
6
11.6k
Available Count
int64
1
31
Q_Score
int64
0
6.79k
Data Science and Machine Learning
int64
0
1
Question
stringlengths
15
29k
Title
stringlengths
11
150
Score
float64
-1
1.2
Database and SQL
int64
0
1
Networking and APIs
int64
0
1
ViewCount
int64
8
6.81M
372,042
2008-12-16T17:32:00.000
2
0
1
0
python,interface,abstract-class
57,158,078
8
false
0
0
Abstract classes are classes that contain one or more abstract methods. Along with abstract methods, Abstract classes can have static, class and instance methods. But in case of interface, it will only have abstract methods not other. Hence it is not compulsory to inherit abstract class but it is compulsory to inherit interface.
2
612
0
What is the difference between abstract class and interface in Python?
Difference between abstract class and interface in Python
0.049958
0
0
442,422
372,102
2008-12-16T17:49:00.000
3
0
1
0
python,regex
372,210
3
false
0
0
Don't use UTF-8 in a regular expression. UTF-8 is a multibyte encoding where some unicode code points are encoded by 2 or more bytes. You may match parts of your string that you didn't plan to match. Instead use unicode strings as suggested.
1
7
0
I'm aware that Python 3 fixes a lot of UTF issues, I am not however able to use Python 3, I am using 2.5.1 I'm trying to regex a document but the document has UTF hyphens in it – rather than -. Python can't match these and if I put them in the regex it throws a wobbly. How can I force Python to use a UTF string or in some way match a character such as that? Thanks for your help
UTF in Python Regex
0.197375
0
0
5,140
372,465
2008-12-16T19:50:00.000
3
1
0
0
python,security,apache,download,lighttpd
372,488
2
false
0
0
You might want to just have your Python script open the file and dump the contents as its output if the user is properly authenticated. Put the files you want to protect in a folder that is outside of the webserver root.
1
0
0
How would I only allow users authenticated via Python code to access certain files on the server? For instance, say I have /static/book.txt which I want to protect. When a user accesses /some/path/that/validates/him, a Python script deems him worthy of accessing /static/book.txt and redirects him to that path. How would I stop users who bypass the script and directly access /static/book.txt?
Protecting online static content
0.291313
0
0
274
372,511
2008-12-16T20:04:00.000
1
1
1
0
python,oop,data-analysis
372,779
14
false
0
0
Actual C++ OO memory overhead is one pointer (4-8 bytes, depending) per object with virtual methods. However, as mentioned in other answers, the default memory allocation overhead from dynamic allocation is likely to be significantly greater than this. If you're doing things halfway reasonably, neither overhead is likely to be significant compared with an 1000*8-byte double array. If you're actually worried about allocation overhead, you can write your own allocator -- but, check first to see if it will actually buy you a significant improvement.
11
2
0
I have a large set of data (a data cube of 250,000 X 1,000 doubles, about a 4 gig file) and I want to manipulate it using a previous set of OOP classes I have written in Python. Currently the data set is already so large that to read into my machine memory I have to at least split it in half so computing overhead is a concern. My OOP classes create new objects (in this case I will need 250,000 new objects, each object is an array of 1,000 doubles) to handle the data. What is the overhead in terms of memory and computing required in creating objects for a generic OOP language? In python? What about in C++? Yes, I realize I could make a new class that is an array. But 1) I already have these classes finished and 2) I put each object that I create back into an array for access later anyways. The question is pedagogical *update: I want to be efficient with time, my time and the computers. I don't want to rewrite a program I already have if I don't have to and spending time optimizing the code wastes my time, I don't care that much if I waste the computers time. I actually do have a 64bit machine with 4Gig ram. The data is an image and I need to do several filters on each pixel.*
What is the object oriented programming computing overhead cost?
0.014285
0
0
3,461
372,511
2008-12-16T20:04:00.000
0
1
1
0
python,oop,data-analysis
372,848
14
false
0
0
Since you can split the data in half and operate on it, I'm assuming that you're working on each record individually? It sounds to me like you need to change your deserialiser to read one record at a time, manipulate it, and then store out the results. Basically you need a string parser class that does a Peek() which returns a char, knows how to skip whitespace, etc. Wrap a class around that that understands your data format, and you should be able to have it spit out an object at a time as it reads the file.
11
2
0
I have a large set of data (a data cube of 250,000 X 1,000 doubles, about a 4 gig file) and I want to manipulate it using a previous set of OOP classes I have written in Python. Currently the data set is already so large that to read into my machine memory I have to at least split it in half so computing overhead is a concern. My OOP classes create new objects (in this case I will need 250,000 new objects, each object is an array of 1,000 doubles) to handle the data. What is the overhead in terms of memory and computing required in creating objects for a generic OOP language? In python? What about in C++? Yes, I realize I could make a new class that is an array. But 1) I already have these classes finished and 2) I put each object that I create back into an array for access later anyways. The question is pedagogical *update: I want to be efficient with time, my time and the computers. I don't want to rewrite a program I already have if I don't have to and spending time optimizing the code wastes my time, I don't care that much if I waste the computers time. I actually do have a 64bit machine with 4Gig ram. The data is an image and I need to do several filters on each pixel.*
What is the object oriented programming computing overhead cost?
0
0
0
3,461
372,511
2008-12-16T20:04:00.000
0
1
1
0
python,oop,data-analysis
372,517
14
false
0
0
Impossible to answer without knowing the shape of the data and the structure that you've designed to contain it.
11
2
0
I have a large set of data (a data cube of 250,000 X 1,000 doubles, about a 4 gig file) and I want to manipulate it using a previous set of OOP classes I have written in Python. Currently the data set is already so large that to read into my machine memory I have to at least split it in half so computing overhead is a concern. My OOP classes create new objects (in this case I will need 250,000 new objects, each object is an array of 1,000 doubles) to handle the data. What is the overhead in terms of memory and computing required in creating objects for a generic OOP language? In python? What about in C++? Yes, I realize I could make a new class that is an array. But 1) I already have these classes finished and 2) I put each object that I create back into an array for access later anyways. The question is pedagogical *update: I want to be efficient with time, my time and the computers. I don't want to rewrite a program I already have if I don't have to and spending time optimizing the code wastes my time, I don't care that much if I waste the computers time. I actually do have a 64bit machine with 4Gig ram. The data is an image and I need to do several filters on each pixel.*
What is the object oriented programming computing overhead cost?
0
0
0
3,461
372,511
2008-12-16T20:04:00.000
0
1
1
0
python,oop,data-analysis
372,801
14
false
0
0
A friend of mine was a professor at MIT and a student asked him why his image analysis program was running so slow. How was it built? Every pixel was an object, and would send messages to its neighbors! If I were you I'd try it in a throw-away program. My suspicion is, unless your classes are very carefully coded, you're going to find it spending a lot of time allocating, initializing, and de-allocating objects, and as Brian said, you might be able to spool the data through a set of re-used objects. Edit: Excuse me. You said you are re-using objects, so that's good. In any case, when you get it running you could profile it or (if you were me) just read the call stack a few random times, and that will answer any questions about where the time goes.
11
2
0
I have a large set of data (a data cube of 250,000 X 1,000 doubles, about a 4 gig file) and I want to manipulate it using a previous set of OOP classes I have written in Python. Currently the data set is already so large that to read into my machine memory I have to at least split it in half so computing overhead is a concern. My OOP classes create new objects (in this case I will need 250,000 new objects, each object is an array of 1,000 doubles) to handle the data. What is the overhead in terms of memory and computing required in creating objects for a generic OOP language? In python? What about in C++? Yes, I realize I could make a new class that is an array. But 1) I already have these classes finished and 2) I put each object that I create back into an array for access later anyways. The question is pedagogical *update: I want to be efficient with time, my time and the computers. I don't want to rewrite a program I already have if I don't have to and spending time optimizing the code wastes my time, I don't care that much if I waste the computers time. I actually do have a 64bit machine with 4Gig ram. The data is an image and I need to do several filters on each pixel.*
What is the object oriented programming computing overhead cost?
0
0
0
3,461
372,511
2008-12-16T20:04:00.000
0
1
1
0
python,oop,data-analysis
372,724
14
false
0
0
Please define "manipulate". If you really want to manipulate 4 gigs of data why do you want to manipulate it by pulling it ALL into memory right away? I mean, who needs 4 gig of RAM anyway? :)
11
2
0
I have a large set of data (a data cube of 250,000 X 1,000 doubles, about a 4 gig file) and I want to manipulate it using a previous set of OOP classes I have written in Python. Currently the data set is already so large that to read into my machine memory I have to at least split it in half so computing overhead is a concern. My OOP classes create new objects (in this case I will need 250,000 new objects, each object is an array of 1,000 doubles) to handle the data. What is the overhead in terms of memory and computing required in creating objects for a generic OOP language? In python? What about in C++? Yes, I realize I could make a new class that is an array. But 1) I already have these classes finished and 2) I put each object that I create back into an array for access later anyways. The question is pedagogical *update: I want to be efficient with time, my time and the computers. I don't want to rewrite a program I already have if I don't have to and spending time optimizing the code wastes my time, I don't care that much if I waste the computers time. I actually do have a 64bit machine with 4Gig ram. The data is an image and I need to do several filters on each pixel.*
What is the object oriented programming computing overhead cost?
0
0
0
3,461
372,511
2008-12-16T20:04:00.000
2
1
1
0
python,oop,data-analysis
372,524
14
false
0
0
I wouldn't consider it fair to blame any shortcomings of your design to OOP. Just like any other programming platform out there OO can be used for both good and less than optimal design. Rarely will this be the fault of the programming model itself. But to try to answer your question: Allocating 250000 new object requires some overhead in all OO language that I'm aware of, so if you can get away with streaming the data through the same instance, you're probably better off.
11
2
0
I have a large set of data (a data cube of 250,000 X 1,000 doubles, about a 4 gig file) and I want to manipulate it using a previous set of OOP classes I have written in Python. Currently the data set is already so large that to read into my machine memory I have to at least split it in half so computing overhead is a concern. My OOP classes create new objects (in this case I will need 250,000 new objects, each object is an array of 1,000 doubles) to handle the data. What is the overhead in terms of memory and computing required in creating objects for a generic OOP language? In python? What about in C++? Yes, I realize I could make a new class that is an array. But 1) I already have these classes finished and 2) I put each object that I create back into an array for access later anyways. The question is pedagogical *update: I want to be efficient with time, my time and the computers. I don't want to rewrite a program I already have if I don't have to and spending time optimizing the code wastes my time, I don't care that much if I waste the computers time. I actually do have a 64bit machine with 4Gig ram. The data is an image and I need to do several filters on each pixel.*
What is the object oriented programming computing overhead cost?
0.028564
0
0
3,461
372,511
2008-12-16T20:04:00.000
0
1
1
0
python,oop,data-analysis
372,658
14
false
0
0
I don't think the question is overhead coming from OO. If we accept C++ as an OO language and remember that the C++ compiler is a preprocessor to C (at least it used to be, when I used C++), anything done in C++ is really done in C. C has very little overhead. So it would depend on the libraries. I think any overhead would come from interpretation, managed execution or memory management. For those that have the tools and the know-how, it would be very easy to find out which is most efficient, C++ or Python. I can't see where C++ would add much avoidable overhead. I don't know much about Python.
11
2
0
I have a large set of data (a data cube of 250,000 X 1,000 doubles, about a 4 gig file) and I want to manipulate it using a previous set of OOP classes I have written in Python. Currently the data set is already so large that to read into my machine memory I have to at least split it in half so computing overhead is a concern. My OOP classes create new objects (in this case I will need 250,000 new objects, each object is an array of 1,000 doubles) to handle the data. What is the overhead in terms of memory and computing required in creating objects for a generic OOP language? In python? What about in C++? Yes, I realize I could make a new class that is an array. But 1) I already have these classes finished and 2) I put each object that I create back into an array for access later anyways. The question is pedagogical *update: I want to be efficient with time, my time and the computers. I don't want to rewrite a program I already have if I don't have to and spending time optimizing the code wastes my time, I don't care that much if I waste the computers time. I actually do have a 64bit machine with 4Gig ram. The data is an image and I need to do several filters on each pixel.*
What is the object oriented programming computing overhead cost?
0
0
0
3,461
372,511
2008-12-16T20:04:00.000
0
1
1
0
python,oop,data-analysis
372,641
14
false
0
0
Like the other posters have stated. I do not believe Objects are going to lend a significant amount of overhead to your process. It will need to store a pointer to the object but the rest of the 'doubles' will be taking 99% of your program's memory. Can you partition this data into much smaller subsets? What is the task that you are trying to accomplish? I would be interested in seeing what you need all the data in memory for. Perhaps you can just serialize it, or use something like lazy evaluation in haskell. Please post a follow up so we can understand your problem domain better.
11
2
0
I have a large set of data (a data cube of 250,000 X 1,000 doubles, about a 4 gig file) and I want to manipulate it using a previous set of OOP classes I have written in Python. Currently the data set is already so large that to read into my machine memory I have to at least split it in half so computing overhead is a concern. My OOP classes create new objects (in this case I will need 250,000 new objects, each object is an array of 1,000 doubles) to handle the data. What is the overhead in terms of memory and computing required in creating objects for a generic OOP language? In python? What about in C++? Yes, I realize I could make a new class that is an array. But 1) I already have these classes finished and 2) I put each object that I create back into an array for access later anyways. The question is pedagogical *update: I want to be efficient with time, my time and the computers. I don't want to rewrite a program I already have if I don't have to and spending time optimizing the code wastes my time, I don't care that much if I waste the computers time. I actually do have a 64bit machine with 4Gig ram. The data is an image and I need to do several filters on each pixel.*
What is the object oriented programming computing overhead cost?
0
0
0
3,461
372,511
2008-12-16T20:04:00.000
3
1
1
0
python,oop,data-analysis
372,566
14
false
0
0
You'd have similar issues with procedural/functional programming languages. How do you store that much data in memory? A struct or array wouldn't work either. You need to take special steps to manage this scale of data. BTW: I wouldn't use this as a reason to pick either an OO language or not.
11
2
0
I have a large set of data (a data cube of 250,000 X 1,000 doubles, about a 4 gig file) and I want to manipulate it using a previous set of OOP classes I have written in Python. Currently the data set is already so large that to read into my machine memory I have to at least split it in half so computing overhead is a concern. My OOP classes create new objects (in this case I will need 250,000 new objects, each object is an array of 1,000 doubles) to handle the data. What is the overhead in terms of memory and computing required in creating objects for a generic OOP language? In python? What about in C++? Yes, I realize I could make a new class that is an array. But 1) I already have these classes finished and 2) I put each object that I create back into an array for access later anyways. The question is pedagogical *update: I want to be efficient with time, my time and the computers. I don't want to rewrite a program I already have if I don't have to and spending time optimizing the code wastes my time, I don't care that much if I waste the computers time. I actually do have a 64bit machine with 4Gig ram. The data is an image and I need to do several filters on each pixel.*
What is the object oriented programming computing overhead cost?
0.042831
0
0
3,461
372,511
2008-12-16T20:04:00.000
0
1
1
0
python,oop,data-analysis
372,595
14
false
0
0
The "overhead" depends largely on the platform and the implementation you chose. Now if you have a memory problem reading millions of data from a multiple Gb file, you're having an algorithm problem where the memory consumption of objects is definitely not the biggest concern, the concern yould be more about how you do fetch, process and store the data.
11
2
0
I have a large set of data (a data cube of 250,000 X 1,000 doubles, about a 4 gig file) and I want to manipulate it using a previous set of OOP classes I have written in Python. Currently the data set is already so large that to read into my machine memory I have to at least split it in half so computing overhead is a concern. My OOP classes create new objects (in this case I will need 250,000 new objects, each object is an array of 1,000 doubles) to handle the data. What is the overhead in terms of memory and computing required in creating objects for a generic OOP language? In python? What about in C++? Yes, I realize I could make a new class that is an array. But 1) I already have these classes finished and 2) I put each object that I create back into an array for access later anyways. The question is pedagogical *update: I want to be efficient with time, my time and the computers. I don't want to rewrite a program I already have if I don't have to and spending time optimizing the code wastes my time, I don't care that much if I waste the computers time. I actually do have a 64bit machine with 4Gig ram. The data is an image and I need to do several filters on each pixel.*
What is the object oriented programming computing overhead cost?
0
0
0
3,461
372,511
2008-12-16T20:04:00.000
0
1
1
0
python,oop,data-analysis
372,706
14
false
0
0
compared to the size of your data set, the overhead of 250K objects is negligible i think you're on the wrong path; don't blame objects for that ;-)
11
2
0
I have a large set of data (a data cube of 250,000 X 1,000 doubles, about a 4 gig file) and I want to manipulate it using a previous set of OOP classes I have written in Python. Currently the data set is already so large that to read into my machine memory I have to at least split it in half so computing overhead is a concern. My OOP classes create new objects (in this case I will need 250,000 new objects, each object is an array of 1,000 doubles) to handle the data. What is the overhead in terms of memory and computing required in creating objects for a generic OOP language? In python? What about in C++? Yes, I realize I could make a new class that is an array. But 1) I already have these classes finished and 2) I put each object that I create back into an array for access later anyways. The question is pedagogical *update: I want to be efficient with time, my time and the computers. I don't want to rewrite a program I already have if I don't have to and spending time optimizing the code wastes my time, I don't care that much if I waste the computers time. I actually do have a 64bit machine with 4Gig ram. The data is an image and I need to do several filters on each pixel.*
What is the object oriented programming computing overhead cost?
0
0
0
3,461
372,885
2008-12-16T21:49:00.000
1
0
0
0
python,mysql
64,762,149
25
false
0
0
First step to get The Library: Open terminal and execute pip install mysql-python-connector. After the installation go the second step. Second Step to import the library: Open your python file and write the following code: import mysql.connector Third step to connect to the server: Write the following code: conn = mysql.connector.connect(host=you host name like localhost or 127.0.0.1, username=your username like root, password = your password) Third step Making the cursor: Making a cursor makes it easy for us to run queries. To make the cursor use the following code: cursor = conn.cursor() Executing queries: For executing queries you can do the following: cursor.execute(query) If the query changes any thing in the table you need to add the following code after the execution of the query: conn.commit() Getting values from a query: If you want to get values from a query then you can do the following: cursor.excecute('SELECT * FROM table_name') for i in cursor: print(i) #Or for i in cursor.fetchall(): print(i) The fetchall() method returns a list with many tuples that contain the values that you requested ,row after row . Closing the connection: To close the connection you should use the following code: conn.close() Handling exception: To Handel exception you can do it Vai the following method: try: #Logic pass except mysql.connector.errors.Error: #Logic pass To use a database: For example you are a account creating system where you are storing the data in a database named blabla, you can just add a database parameter to the connect() method ,like mysql.connector.connect(database = database name) don't remove other informations like host,username,password.
1
1,242
0
How do I connect to a MySQL database using a python program?
How do I connect to a MySQL Database in Python?
0.008
1
0
1,369,727
373,383
2008-12-17T01:19:00.000
0
1
0
0
python,api,rest,geocoding
2,229,732
9
false
0
0
You can have better look in Geopy module.And it is worth enough to use as it contains Google map, yahoo map geocoders with which you can implement geocodings.
1
23
0
I'm using python and I need to map locations like "Bloomington, IN" to GPS coordinates so I can measure distances between them. What Geocoding libraries/APIs do you recommend? Solutions in other languages are also welcome.
Geocoding libraries
0
0
1
13,754
373,406
2008-12-17T01:38:00.000
2
1
0
0
javascript,python,sandbox
373,415
1
false
1
0
I use Lua for this, but it's directed at a Lua capable community. So my answer would be who are your users? If your users are internal, like my case, and proficient with Python use Python. However if this is something for the world wide web, I'd probably choose javascript, because its the lingua franca, (every developer knows it, and its easy to pickup). As for an Engine... well V8 would be nice, but its not 100% thread safe, in that you can't run several engine within the same process in a lock free manner, as you can with SpiderMonkey. So You might want to use that. Also since javascript is sandboxed by default you won't have to worry about implementing much on your side.
1
7
0
Beyond offering an API for my website, I'd like to offer users the ability to write simple scripts that would run on my servers . The scripts would have access to objects owned by the user and be able to manipulate, modify, and otherwise process their data. I'd like to be able to limit resources taken by these scripts at a fine level (eg. max execution time should be 100ms). I'd also like to ensure a secure sandbox such that each user will have access to only a limited set of data and resources, and be prevented from accessing disk, other people's data, etc. Generally the scripts will be very simple (eg. create the sum or average of the values that match certain criteria), and they'll often be used in templates (eg. fill in the value of this cell or html element with the average or sum). Ideally I'd like to use a sandboxed subset of a well know, commonly available programming language so it's easy for users to pick up. The backend is written in Python, so a Python based language could have benefits, but I'm open to other languages and technologies. Javascript is also attractive due to its simple nature and common availability. The languages should support creation of DSLs and libraries. The target audience is a general user base for a web based application, not necessarily very technical. In other words, it's not targeted at a base with particular knowledge of any particular programming language. My expectation is a subset of users will create scripts that will be used by the larger majority. Any ideas or recommendations for the language and technology? Any examples of others trying this and the successes and failures they encountered?
Secure, sandboxable user exposed programming language / environment?
0.379949
0
0
421
374,763
2008-12-17T14:49:00.000
1
1
1
0
python,coding-style
374,860
5
false
0
0
I've seen it done both ways. Coming from an Objective-C background, I usually do foo()/set_foo() if I can't use a property (although I try to use properties whenever possible). It doesn't really matter that much, though, as long as you're consistent. (Of course, in your example, I wouldn't call the method get_city_by_postalcode() at all; I'd probably go with translate_postalcode or something similar that uses a better action verb in the name.)
3
18
0
In Python properties are used instead of the Java-style getters, setters. So one rarely sees get... or set.. methods in the public interfaces of classes. But in cases were a property is not appropriate one might still end up with methods that behave like getters or setters. Now my questions: Should these method names start with get_ / set_? Or is this unpythonic vebosity since it is often obvious what is meant (and one can still use the docstring to clarify non-obvious situations)? This might be a matter of personal taste, but I would be interested in what the majority thinks about this? What would you prefer as an API user? Example: Say we have an object representing multiple cities. One might have a method get_city_by_postalcode(postalcode) or one could use the shorter name city_by_postalcode. I tend towards the later.
Should I use get_/set_ prefixes in Python method names?
0.039979
0
0
4,305
374,763
2008-12-17T14:49:00.000
0
1
1
0
python,coding-style
375,661
5
false
0
0
If I have to use a getter/setter, I like it this way: Suppose you have a variable self._x. Then x() would return the value of self._x, and setX(x) would set the value of self._x
3
18
0
In Python properties are used instead of the Java-style getters, setters. So one rarely sees get... or set.. methods in the public interfaces of classes. But in cases were a property is not appropriate one might still end up with methods that behave like getters or setters. Now my questions: Should these method names start with get_ / set_? Or is this unpythonic vebosity since it is often obvious what is meant (and one can still use the docstring to clarify non-obvious situations)? This might be a matter of personal taste, but I would be interested in what the majority thinks about this? What would you prefer as an API user? Example: Say we have an object representing multiple cities. One might have a method get_city_by_postalcode(postalcode) or one could use the shorter name city_by_postalcode. I tend towards the later.
Should I use get_/set_ prefixes in Python method names?
0
0
0
4,305
374,763
2008-12-17T14:49:00.000
4
1
1
0
python,coding-style
374,856
5
true
0
0
I think shorter is better, so I tend to prefer the later. But what's important is to consistent with your project: don't mix the two methods. If you jump into someone else's project, keep what the other developers chose initially.
3
18
0
In Python properties are used instead of the Java-style getters, setters. So one rarely sees get... or set.. methods in the public interfaces of classes. But in cases were a property is not appropriate one might still end up with methods that behave like getters or setters. Now my questions: Should these method names start with get_ / set_? Or is this unpythonic vebosity since it is often obvious what is meant (and one can still use the docstring to clarify non-obvious situations)? This might be a matter of personal taste, but I would be interested in what the majority thinks about this? What would you prefer as an API user? Example: Say we have an object representing multiple cities. One might have a method get_city_by_postalcode(postalcode) or one could use the shorter name city_by_postalcode. I tend towards the later.
Should I use get_/set_ prefixes in Python method names?
1.2
0
0
4,305
375,620
2008-12-17T18:54:00.000
0
1
0
1
python,ftp,ftplib
375,650
4
false
0
0
You can't know when the OS copy is done. It could slow down or wait. For absolute certainty, you really need two files. The massive file. And a tiny trigger file. They can mess with the massive file all they want. But when they touch the trigger file, you're downloading both. If you can't get a trigger, you have to balance the time required to poll vs. the time required to download. Do this. Get a listing. Check timestamps. Check sizes vs. previous size of file. If size isn't even close, it's being copied right now. Wait; loop on this step until size is close to previous size. While you're not done: a. Get the file. b. Get a listing AGAIN. Check the size of the new listing, previous listing and your file. If they agree: you're done. If they don't agree: file changed while you were downloading; you're not done.
4
4
0
We have a ftp system setup to monitor/download from remote ftp servers that are not under our control. The script connects to the remote ftp, and grabs the file names of files on the server, we then check to see if its something that has already been downloaded. If it hasn't been downloaded then we download the file and add it to the list. We recently ran into an issue, where someone on the remote ftp side, will copy in a massive single file(>1GB) then the script will wake up see a new file and begin downloading the file that is being copied in. What is the best way to check this? I was thinking of grabbing the file size waiting a few seconds checking the file size again and see if it has increased, if it hasn't then we download it. But since time is of the concern, we can't wait a few seconds for every single file set and see if it's file size has increased. What would be the best way to go about this, currently everything is done via pythons ftplib, how can we do this aside from using the aforementioned method. Yet again let me reiterate this, we have 0 control over the remote ftp sites. Thanks. UPDATE1: I was thinking what if i tried to rename it... since we have full permissions on the ftp, if the file upload is in progress would the rename command fail? We don't have any real options here... do we? UPDATE2: Well here's something interesting some of the ftps we tested on appear to automatically allocate the space once the transfer starts. E.g. If i transfer a 200mb file to the ftp server. While the transfer is active if i connect to the ftp server and do a size while the upload is happening. It shows 200mb for the size. Even though the file is only like 10% complete. Permissions also seem to be randomly set the FTP Server that comes with IIS sets the permissions AFTER the file is finished copying. While some of the other older ftp servers set it as soon as you send the file. :'(
Prevent ftplib from Downloading a File in Progress?
0
0
0
1,585
375,620
2008-12-17T18:54:00.000
5
1
0
1
python,ftp,ftplib
375,800
4
true
0
0
“Damn the torpedoes! Full speed ahead!” Just download the file. If it is a large file then after the download completes wait as long as is reasonable for your scenario and continue the download from the point it stopped. Repeat until there is no more stuff to download.
4
4
0
We have a ftp system setup to monitor/download from remote ftp servers that are not under our control. The script connects to the remote ftp, and grabs the file names of files on the server, we then check to see if its something that has already been downloaded. If it hasn't been downloaded then we download the file and add it to the list. We recently ran into an issue, where someone on the remote ftp side, will copy in a massive single file(>1GB) then the script will wake up see a new file and begin downloading the file that is being copied in. What is the best way to check this? I was thinking of grabbing the file size waiting a few seconds checking the file size again and see if it has increased, if it hasn't then we download it. But since time is of the concern, we can't wait a few seconds for every single file set and see if it's file size has increased. What would be the best way to go about this, currently everything is done via pythons ftplib, how can we do this aside from using the aforementioned method. Yet again let me reiterate this, we have 0 control over the remote ftp sites. Thanks. UPDATE1: I was thinking what if i tried to rename it... since we have full permissions on the ftp, if the file upload is in progress would the rename command fail? We don't have any real options here... do we? UPDATE2: Well here's something interesting some of the ftps we tested on appear to automatically allocate the space once the transfer starts. E.g. If i transfer a 200mb file to the ftp server. While the transfer is active if i connect to the ftp server and do a size while the upload is happening. It shows 200mb for the size. Even though the file is only like 10% complete. Permissions also seem to be randomly set the FTP Server that comes with IIS sets the permissions AFTER the file is finished copying. While some of the other older ftp servers set it as soon as you send the file. :'(
Prevent ftplib from Downloading a File in Progress?
1.2
0
0
1,585
375,620
2008-12-17T18:54:00.000
0
1
0
1
python,ftp,ftplib
375,716
4
false
0
0
If you are dealing with multiple files, you could get the list of all the sizes at once, wait ten seconds, and see which are the same. Whichever are still the same should be safe to download.
4
4
0
We have a ftp system setup to monitor/download from remote ftp servers that are not under our control. The script connects to the remote ftp, and grabs the file names of files on the server, we then check to see if its something that has already been downloaded. If it hasn't been downloaded then we download the file and add it to the list. We recently ran into an issue, where someone on the remote ftp side, will copy in a massive single file(>1GB) then the script will wake up see a new file and begin downloading the file that is being copied in. What is the best way to check this? I was thinking of grabbing the file size waiting a few seconds checking the file size again and see if it has increased, if it hasn't then we download it. But since time is of the concern, we can't wait a few seconds for every single file set and see if it's file size has increased. What would be the best way to go about this, currently everything is done via pythons ftplib, how can we do this aside from using the aforementioned method. Yet again let me reiterate this, we have 0 control over the remote ftp sites. Thanks. UPDATE1: I was thinking what if i tried to rename it... since we have full permissions on the ftp, if the file upload is in progress would the rename command fail? We don't have any real options here... do we? UPDATE2: Well here's something interesting some of the ftps we tested on appear to automatically allocate the space once the transfer starts. E.g. If i transfer a 200mb file to the ftp server. While the transfer is active if i connect to the ftp server and do a size while the upload is happening. It shows 200mb for the size. Even though the file is only like 10% complete. Permissions also seem to be randomly set the FTP Server that comes with IIS sets the permissions AFTER the file is finished copying. While some of the other older ftp servers set it as soon as you send the file. :'(
Prevent ftplib from Downloading a File in Progress?
0
0
0
1,585
375,620
2008-12-17T18:54:00.000
0
1
0
1
python,ftp,ftplib
375,705
4
false
0
0
As you say you have 0 control over the servers and can't make your clients post trigger files as suggested by S. Lott, you must deal with the imperfect solution and risk incomplete file transmission, perhaps by waiting for a while and compare file sizes before and after. You can try to rename as you suggested, but as you have 0 control you can't be sure that the ftp-server-administrator (or their successor) doesn't change platforms or ftp servers or restricts your permissions. Sorry.
4
4
0
We have a ftp system setup to monitor/download from remote ftp servers that are not under our control. The script connects to the remote ftp, and grabs the file names of files on the server, we then check to see if its something that has already been downloaded. If it hasn't been downloaded then we download the file and add it to the list. We recently ran into an issue, where someone on the remote ftp side, will copy in a massive single file(>1GB) then the script will wake up see a new file and begin downloading the file that is being copied in. What is the best way to check this? I was thinking of grabbing the file size waiting a few seconds checking the file size again and see if it has increased, if it hasn't then we download it. But since time is of the concern, we can't wait a few seconds for every single file set and see if it's file size has increased. What would be the best way to go about this, currently everything is done via pythons ftplib, how can we do this aside from using the aforementioned method. Yet again let me reiterate this, we have 0 control over the remote ftp sites. Thanks. UPDATE1: I was thinking what if i tried to rename it... since we have full permissions on the ftp, if the file upload is in progress would the rename command fail? We don't have any real options here... do we? UPDATE2: Well here's something interesting some of the ftps we tested on appear to automatically allocate the space once the transfer starts. E.g. If i transfer a 200mb file to the ftp server. While the transfer is active if i connect to the ftp server and do a size while the upload is happening. It shows 200mb for the size. Even though the file is only like 10% complete. Permissions also seem to be randomly set the FTP Server that comes with IIS sets the permissions AFTER the file is finished copying. While some of the other older ftp servers set it as soon as you send the file. :'(
Prevent ftplib from Downloading a File in Progress?
0
0
0
1,585
377,017
2008-12-18T05:55:00.000
0
1
0
1
python,path
377,590
15
false
0
0
So basically you want to find a file in mounted filesystem (not necessarily in PATH directories only) and check if it is executable. This translates to following plan: enumerate all files in locally mounted filesystems match results with name pattern for each file found check if it is executable I'd say, doing this in a portable way will require lots of computing power and time. Is it really what you need?
1
337
0
In Python, is there a portable and simple way to test if an executable program exists? By simple I mean something like the which command which would be just perfect. I don't want to search PATH manually or something involving trying to execute it with Popen & al and see if it fails (that's what I'm doing now, but imagine it's launchmissiles)
Test if executable exists in Python?
0
0
0
167,325
377,362
2008-12-18T09:41:00.000
0
0
1
0
python
377,418
2
false
0
0
Spaces vs. Tabs issue...ugh. >.> Well, atleast it works now. I admit that I kind of miss the braces from C instead of forced-indentation. It's quite handy as a prototyping language though. Maybe I'll grow to love it more when I get a better grasp of it.
2
1
0
I have a block of code that basically intializes several classes, but they are placed in a sequential order, as later ones reference early ones. For some reason the last one initializes before the first one...it seems to me there is some sort of threading going on. What I need to know is how can I stop it from doing this? Is there some way to make a class init do something similar to sending a return value? Or maybe I could use the class in an if statement of some sort to check if the class has already been initialized? I'm a bit new to Python and am migrating from C, so I'm still getting used to the little differences like naming conventions.
Code not waiting for class initialization!
0
0
0
174
377,362
2008-12-18T09:41:00.000
0
0
1
0
python
377,382
2
true
0
0
Python upto 3.0 has a global lock, so everything is running in a single thread and in sequence. My guess is that some side effect initializes the last class from a different place than you expect. Throw an exception in __init__ of that last class to see where it gets called.
2
1
0
I have a block of code that basically intializes several classes, but they are placed in a sequential order, as later ones reference early ones. For some reason the last one initializes before the first one...it seems to me there is some sort of threading going on. What I need to know is how can I stop it from doing this? Is there some way to make a class init do something similar to sending a return value? Or maybe I could use the class in an if statement of some sort to check if the class has already been initialized? I'm a bit new to Python and am migrating from C, so I'm still getting used to the little differences like naming conventions.
Code not waiting for class initialization!
1.2
0
0
174
377,454
2008-12-18T10:20:00.000
115
0
1
0
python,timer,sleep
377,546
6
false
0
0
Note that if you rely on sleep taking exactly 50 ms, you won't get that. It will just be about it.
1
711
0
How do I get my Python program to sleep for 50 milliseconds?
How do I get my program to sleep for 50 milliseconds?
1
0
0
671,063
378,564
2008-12-18T17:27:00.000
2
0
1
0
python,asynchronous
378,836
3
true
0
0
Also have a look at the Asynchronous Completion Token and ActiveObject patterns.
1
8
0
Are there any sorts of useful idioms I can make use of when writing an API that is asynchronous? I would like to standardize on something as I seem to be using a few different styles throughout. It seems hard to make asynchronous code simple; I suppose this is because asynchronous operations are anything but. At the most basic level, the user of the API must be able to: Have data pushed to them as it becomes available Check the status of the asynchronous operation Be notified of errors that occur Wait for completion (converting the asynchronous operation to a synchronous one) My classes support several asynchronous operations. I have been putting some of the status/error callbacks in the class around it, but the class is becoming gunked up with a lot of incidental fields, as well as getting too large. I am curious if anyone has used an asynchronous API they found to be well-organized. I have looked at .NET's Begin/EndAsyncOperation + AsyncResult design, as well as some classes in Java (e.g. Future). This is being written in Python, so it remains very flexible. There is a caveat: some of these asynchronous operations are being marshaled to a remote machine and executed over there. Thus, not every operation necessarily executes in a separate thread.
Idiomatic asynchronous design
1.2
0
0
831
379,338
2008-12-18T21:23:00.000
4
0
0
0
python,cherrypy,stringtemplate
467,736
2
false
1
0
Based on the tutorials for both, it looks pretty straightforward: import stringtemplate import cherrypy class HelloWorld(object): def index(self): hello = stringtemplate.StringTemplate("Hello, $name$") hello["name"] = "World" return str(hello) index.exposed = True cherrypy.quickstart(HelloWorld()) You'll probably want to have the CherryPy functions find the StringTemplate's in some location on disk instead, but the general idea will be like this. Django is conceptually similar: url's are mapped to python functions, and the python functions generally build up a context dictionary, render a template with that context object, and return the result.
2
2
0
I love the StringTemplate engine, and I love the CherryPy web server, and I know that they can be integrated. Who has done it? How? EDIT: The TurboGears framework takes the CherryPy web server and bundles other related components such as a template engine, data access tools, JavaScript kit, etc. I am interested in MochiKit, demand CherryPy, but I don't want any other template engine than StringTemplate (architecture is critical--I don't want another broken/bad template engine). Therefore, it would be acceptable to answer this question by addressing how to integrate StringTemplate with TurboGears. It may also be acceptable to answer this question by addressing how to use CherryPy and StringTemplate in the Google App Engine. Thanks.
How to integrate the StringTemplate engine into the CherryPy web server
0.379949
0
0
1,241
379,338
2008-12-18T21:23:00.000
0
0
0
0
python,cherrypy,stringtemplate
463,042
2
false
1
0
Rob, There's reason behind people's selection of tools. StringTemplate is not terribly popular for Python, there are templating engines that are much better supported and with a much wider audience. If you don't like Kid, there's also Django's templating, Jinja, Cheetah and others. Perhaps you can find in one of them the features you like so much in StringTemplate and live happily ever after.
2
2
0
I love the StringTemplate engine, and I love the CherryPy web server, and I know that they can be integrated. Who has done it? How? EDIT: The TurboGears framework takes the CherryPy web server and bundles other related components such as a template engine, data access tools, JavaScript kit, etc. I am interested in MochiKit, demand CherryPy, but I don't want any other template engine than StringTemplate (architecture is critical--I don't want another broken/bad template engine). Therefore, it would be acceptable to answer this question by addressing how to integrate StringTemplate with TurboGears. It may also be acceptable to answer this question by addressing how to use CherryPy and StringTemplate in the Google App Engine. Thanks.
How to integrate the StringTemplate engine into the CherryPy web server
0
0
0
1,241
379,442
2008-12-18T21:52:00.000
1
0
0
0
c++,python,performance,drawing,wxpython
380,558
3
false
0
1
For drawing, people have suggested PyGame. I like PyGame, its easy to work with and works well. Other choices would be Pyglet, or using PyOpenGL (you can most likely draw to a wx widget too, though I've never done it). Personally, I'd do it in Python using whatever library I'm most familiar with (in my case, I'd use pygtk and cairo) and worry about performance only when it becomes a problem - then profile and optimize the bottleneck, if its Python code thats slow, I'll know which bits to run in C instead.
1
6
0
I'm looking into writing a wxWidget that displays a graphical node network, and therefore does a lot of drawing operations. I know that using Python to do it is going to be slower, but I'd rather get it working and port it later when its functional. Ideally, if the performance hit isn't too great, I'd prefer to keep the codebase in Python for easy updates. What I'm wondering is how much slower should I expect things to go? I realize this is vague and open ended, but I just need a sense of what to expect. Will drawing 500 circles bog down? Will it be noticeable at all? What are your experiences?
How much slower is a wxWidget written in Python versus C++?
0.066568
0
0
1,255
380,870
2008-12-19T12:42:00.000
27
0
1
0
python,process,locking,mutual-exclusion
380,876
23
false
0
0
I don't know if it's pythonic enough, but in the Java world listening on a defined port is a pretty widely used solution, as it works on all major platforms and doesn't have any problems with crashing programs. Another advantage of listening to a port is that you could send a command to the running instance. For example when the users starts the program a second time, you could send the running instance a command to tell it to open another window (that's what Firefox does, for example. I don't know if they use TCP ports or named pipes or something like that, 'though).
4
145
0
Is there a Pythonic way to have only one instance of a program running? The only reasonable solution I've come up with is trying to run it as a server on some port, then second program trying to bind to same port - fails. But it's not really a great idea, maybe there's something more lightweight than this? (Take into consideration that program is expected to fail sometimes, i.e. segfault - so things like "lock file" won't work)
Make sure only a single instance of a program is running
1
0
0
92,672
380,870
2008-12-19T12:42:00.000
5
0
1
0
python,process,locking,mutual-exclusion
380,894
23
false
0
0
This may work. Attempt create a PID file to a known location. If you fail, someone has the file locked, you're done. When you finish normally, close and remove the PID file, so someone else can overwrite it. You can wrap your program in a shell script that removes the PID file even if your program crashes. You can, also, use the PID file to kill the program if it hangs.
4
145
0
Is there a Pythonic way to have only one instance of a program running? The only reasonable solution I've come up with is trying to run it as a server on some port, then second program trying to bind to same port - fails. But it's not really a great idea, maybe there's something more lightweight than this? (Take into consideration that program is expected to fail sometimes, i.e. segfault - so things like "lock file" won't work)
Make sure only a single instance of a program is running
0.043451
0
0
92,672
380,870
2008-12-19T12:42:00.000
2
0
1
0
python,process,locking,mutual-exclusion
4,337,301
23
false
0
0
I'm posting this as an answer because I'm a new user and Stack Overflow won't let me vote yet. Sorin Sbarnea's solution works for me under OS X, Linux and Windows, and I am grateful for it. However, tempfile.gettempdir() behaves one way under OS X and Windows and another under other some/many/all(?) *nixes (ignoring the fact that OS X is also Unix!). The difference is important to this code. OS X and Windows have user-specific temp directories, so a tempfile created by one user isn't visible to another user. By contrast, under many versions of *nix (I tested Ubuntu 9, RHEL 5, OpenSolaris 2008 and FreeBSD 8), the temp dir is /tmp for all users. That means that when the lockfile is created on a multi-user machine, it's created in /tmp and only the user who creates the lockfile the first time will be able to run the application. A possible solution is to embed the current username in the name of the lock file. It's worth noting that the OP's solution of grabbing a port will also misbehave on a multi-user machine.
4
145
0
Is there a Pythonic way to have only one instance of a program running? The only reasonable solution I've come up with is trying to run it as a server on some port, then second program trying to bind to same port - fails. But it's not really a great idea, maybe there's something more lightweight than this? (Take into consideration that program is expected to fail sometimes, i.e. segfault - so things like "lock file" won't work)
Make sure only a single instance of a program is running
0.01739
0
0
92,672
380,870
2008-12-19T12:42:00.000
1
0
1
0
python,process,locking,mutual-exclusion
17,838,832
23
false
0
0
I keep suspecting there ought to be a good POSIXy solution using process groups, without having to hit the file system, but I can't quite nail it down. Something like: On startup, your process sends a 'kill -0' to all processes in a particular group. If any such processes exist, it exits. Then it joins the group. No other processes use that group. However, this has a race condition - multiple processes could all do this at precisely the same time and all end up joining the group and running simultaneously. By the time you've added some sort of mutex to make it watertight, you no longer need the process groups. This might be acceptable if your process only gets started by cron, once every minute or every hour, but it makes me a bit nervous that it would go wrong precisely on the day when you don't want it to. I guess this isn't a very good solution after all, unless someone can improve on it?
4
145
0
Is there a Pythonic way to have only one instance of a program running? The only reasonable solution I've come up with is trying to run it as a server on some port, then second program trying to bind to same port - fails. But it's not really a great idea, maybe there's something more lightweight than this? (Take into consideration that program is expected to fail sometimes, i.e. segfault - so things like "lock file" won't work)
Make sure only a single instance of a program is running
0.008695
0
0
92,672
383,738
2008-12-20T21:04:00.000
2
0
0
0
python,sockets,wsgi,httplib2,werkzeug
52,826,181
4
false
1
0
I had the same issue however with doing an upload of a very large file using a python-requests client posting to a nginx+uwsgi backend. What ended up being the cause was the the backend had a cap on the max file size for uploads lower than what the client was trying to send. The error never showed up in our uwsgi logs since this limit was actually one imposed by nginx. Upping the limit in nginx removed the error.
3
39
0
We're developing a Python web service and a client web site in parallel. When we make an HTTP request from the client to the service, one call consistently raises a socket.error in socket.py, in read: (104, 'Connection reset by peer') When I listen in with wireshark, the "good" and "bad" responses look very similar: Because of the size of the OAuth header, the request is split into two packets. The service responds to both with ACK The service sends the response, one packet per header (HTTP/1.0 200 OK, then the Date header, etc.). The client responds to each with ACK. (Good request) the server sends a FIN, ACK. The client responds with a FIN, ACK. The server responds ACK. (Bad request) the server sends a RST, ACK, the client doesn't send a TCP response, the socket.error is raised on the client side. Both the web service and the client are running on a Gentoo Linux x86-64 box running glibc-2.6.1. We're using Python 2.5.2 inside the same virtual_env. The client is a Django 1.0.2 app that is calling httplib2 0.4.0 to make requests. We're signing requests with the OAuth signing algorithm, with the OAuth token always set to an empty string. The service is running Werkzeug 0.3.1, which is using Python's wsgiref.simple_server. I ran the WSGI app through wsgiref.validator with no issues. It seems like this should be easy to debug, but when I trace through a good request on the service side, it looks just like the bad request, in the socket._socketobject.close() function, turning delegate methods into dummy methods. When the send or sendto (can't remember which) method is switched off, the FIN or RST is sent, and the client starts processing. "Connection reset by peer" seems to place blame on the service, but I don't trust httplib2 either. Can the client be at fault? ** Further debugging - Looks like server on Linux ** I have a MacBook, so I tried running the service on one and the client website on the other. The Linux client calls the OS X server without the bug (FIN ACK). The OS X client calls the Linux service with the bug (RST ACK, and a (54, 'Connection reset by peer')). So, it looks like it's the service running on Linux. Is it x86_64? A bad glibc? wsgiref? Still looking... ** Further testing - wsgiref looks flaky ** We've gone to production with Apache and mod_wsgi, and the connection resets have gone away. See my answer below, but my advice is to log the connection reset and retry. This will let your server run OK in development mode, and solidly in production.
104, 'Connection reset by peer' socket error, or When does closing a socket result in a RST rather than FIN?
0.099668
0
1
140,801
383,738
2008-12-20T21:04:00.000
11
0
0
0
python,sockets,wsgi,httplib2,werkzeug
481,952
4
false
1
0
Don't use wsgiref for production. Use Apache and mod_wsgi, or something else. We continue to see these connection resets, sometimes frequently, with wsgiref (the backend used by the werkzeug test server, and possibly others like the Django test server). Our solution was to log the error, retry the call in a loop, and give up after ten failures. httplib2 tries twice, but we needed a few more. They seem to come in bunches as well - adding a 1 second sleep might clear the issue. We've never seen a connection reset when running through Apache and mod_wsgi. I don't know what they do differently, (maybe they just mask them), but they don't appear. When we asked the local dev community for help, someone confirmed that they see a lot of connection resets with wsgiref that go away on the production server. There's a bug there, but it is going to be hard to find it.
3
39
0
We're developing a Python web service and a client web site in parallel. When we make an HTTP request from the client to the service, one call consistently raises a socket.error in socket.py, in read: (104, 'Connection reset by peer') When I listen in with wireshark, the "good" and "bad" responses look very similar: Because of the size of the OAuth header, the request is split into two packets. The service responds to both with ACK The service sends the response, one packet per header (HTTP/1.0 200 OK, then the Date header, etc.). The client responds to each with ACK. (Good request) the server sends a FIN, ACK. The client responds with a FIN, ACK. The server responds ACK. (Bad request) the server sends a RST, ACK, the client doesn't send a TCP response, the socket.error is raised on the client side. Both the web service and the client are running on a Gentoo Linux x86-64 box running glibc-2.6.1. We're using Python 2.5.2 inside the same virtual_env. The client is a Django 1.0.2 app that is calling httplib2 0.4.0 to make requests. We're signing requests with the OAuth signing algorithm, with the OAuth token always set to an empty string. The service is running Werkzeug 0.3.1, which is using Python's wsgiref.simple_server. I ran the WSGI app through wsgiref.validator with no issues. It seems like this should be easy to debug, but when I trace through a good request on the service side, it looks just like the bad request, in the socket._socketobject.close() function, turning delegate methods into dummy methods. When the send or sendto (can't remember which) method is switched off, the FIN or RST is sent, and the client starts processing. "Connection reset by peer" seems to place blame on the service, but I don't trust httplib2 either. Can the client be at fault? ** Further debugging - Looks like server on Linux ** I have a MacBook, so I tried running the service on one and the client website on the other. The Linux client calls the OS X server without the bug (FIN ACK). The OS X client calls the Linux service with the bug (RST ACK, and a (54, 'Connection reset by peer')). So, it looks like it's the service running on Linux. Is it x86_64? A bad glibc? wsgiref? Still looking... ** Further testing - wsgiref looks flaky ** We've gone to production with Apache and mod_wsgi, and the connection resets have gone away. See my answer below, but my advice is to log the connection reset and retry. This will let your server run OK in development mode, and solidly in production.
104, 'Connection reset by peer' socket error, or When does closing a socket result in a RST rather than FIN?
1
0
1
140,801
383,738
2008-12-20T21:04:00.000
3
0
0
0
python,sockets,wsgi,httplib2,werkzeug
384,415
4
false
1
0
Normally, you'd get an RST if you do a close which doesn't linger (i.e. in which data can be discarded by the stack if it hasn't been sent and ACK'd) and a normal FIN if you allow the close to linger (i.e. the close waits for the data in transit to be ACK'd). Perhaps all you need to do is set your socket to linger so that you remove the race condition between a non lingering close done on the socket and the ACKs arriving?
3
39
0
We're developing a Python web service and a client web site in parallel. When we make an HTTP request from the client to the service, one call consistently raises a socket.error in socket.py, in read: (104, 'Connection reset by peer') When I listen in with wireshark, the "good" and "bad" responses look very similar: Because of the size of the OAuth header, the request is split into two packets. The service responds to both with ACK The service sends the response, one packet per header (HTTP/1.0 200 OK, then the Date header, etc.). The client responds to each with ACK. (Good request) the server sends a FIN, ACK. The client responds with a FIN, ACK. The server responds ACK. (Bad request) the server sends a RST, ACK, the client doesn't send a TCP response, the socket.error is raised on the client side. Both the web service and the client are running on a Gentoo Linux x86-64 box running glibc-2.6.1. We're using Python 2.5.2 inside the same virtual_env. The client is a Django 1.0.2 app that is calling httplib2 0.4.0 to make requests. We're signing requests with the OAuth signing algorithm, with the OAuth token always set to an empty string. The service is running Werkzeug 0.3.1, which is using Python's wsgiref.simple_server. I ran the WSGI app through wsgiref.validator with no issues. It seems like this should be easy to debug, but when I trace through a good request on the service side, it looks just like the bad request, in the socket._socketobject.close() function, turning delegate methods into dummy methods. When the send or sendto (can't remember which) method is switched off, the FIN or RST is sent, and the client starts processing. "Connection reset by peer" seems to place blame on the service, but I don't trust httplib2 either. Can the client be at fault? ** Further debugging - Looks like server on Linux ** I have a MacBook, so I tried running the service on one and the client website on the other. The Linux client calls the OS X server without the bug (FIN ACK). The OS X client calls the Linux service with the bug (RST ACK, and a (54, 'Connection reset by peer')). So, it looks like it's the service running on Linux. Is it x86_64? A bad glibc? wsgiref? Still looking... ** Further testing - wsgiref looks flaky ** We've gone to production with Apache and mod_wsgi, and the connection resets have gone away. See my answer below, but my advice is to log the connection reset and retry. This will let your server run OK in development mode, and solidly in production.
104, 'Connection reset by peer' socket error, or When does closing a socket result in a RST rather than FIN?
0.148885
0
1
140,801
384,333
2008-12-21T10:48:00.000
3
0
0
0
python,django,project,structure
388,021
5
false
1
0
A good question to ask yourself when deciding whether or not to write an app is "could I use this in another project?". If you think you could, then consider what it would take to make the application as independent as possible; How can you reduce the dependancies so that the app doesn't rely on anything specific to a particular project. Some of the ways you can do this are: Giving each app its own urls.py Allowing model types to be passed in as parameters rather than explicitly declaring what models are used in your views. Generic views use this principle. Make your templates easily overridden by having some sort of template_name parameter passed in your urls.py Make sure you can do reverse url lookups with your objects and views. This means naming your views in the urls.py and creating get_absolute_url methods on your models. In some cases like Tagging, GenericForeignKeys can be used to associate a model in your app to any other model, regardless of whether it has ForeignKeys "looking back" at it.
3
7
0
I just wanted to try to build a project with django. Therefore I have a (basic) question on how to manage such a project. Since I cannot find any guidelines or so on how to split a project into applications. Let's take a kind of SO as an example. Which applications would you use? I'd say there should be the applications "users" and "questions". But what if there was a topic system with static articles, too. Maybe they also could receive votes. How to build the apps structure then? One app for "questions", "votes" and "topics" or just one app "content"? I have no idea what to do. Maybe it's because I know not very much about Django yet, but I'm interested either...
How do you manage your Django applications?
0.119427
0
0
1,848
384,333
2008-12-21T10:48:00.000
0
0
0
0
python,django,project,structure
384,377
5
false
1
0
I'll tell you how I am approaching such question: I usually sit with a sheet of paper and draw the boxes (functionalities) and arrows (interdependencies between functionalities). I am sure there are methodologies or other things that could help you, but my approach usually works for me (YMMV, of course). Knowing what a site is supposed to be is basic, though. ;)
3
7
0
I just wanted to try to build a project with django. Therefore I have a (basic) question on how to manage such a project. Since I cannot find any guidelines or so on how to split a project into applications. Let's take a kind of SO as an example. Which applications would you use? I'd say there should be the applications "users" and "questions". But what if there was a topic system with static articles, too. Maybe they also could receive votes. How to build the apps structure then? One app for "questions", "votes" and "topics" or just one app "content"? I have no idea what to do. Maybe it's because I know not very much about Django yet, but I'm interested either...
How do you manage your Django applications?
0
0
0
1,848
384,333
2008-12-21T10:48:00.000
3
0
0
0
python,django,project,structure
384,494
5
false
1
0
Just like any set of dependencies... try to find the most useful stand-alone aspects of the project and make those stand-alone apps. Other Django Apps will have higher level functionality, and reuse the parts of the lowest level apps that you have set up. In my project, I have a calendar app with its own Event object in its models. I also have a carpool database set up, and for the departure time and the duration I use the calendar's Event object right in my RideShare tables. The carpooling database is calendar-aware, and gets all the nice .ics export and calendar views from the calendar app for 'free.' There are some tricks to getting the Apps reusable, like naming the templates directory: project/app2/templates/app2/index.html. This lets you refer to app2/index.html from any other app, and get the right template. I picked that one up looking at the built-in reusable apps in Django itself. Pinax is a bit of a monster size-wise but it also demonstrates a nice reusable App structure. If in doubt, forget about reusable apps for now. Put all your messages and polls in one app and get through one rev. You'll discover during the process what steps feel unnecessary, and could be broken out as something stand-alone in the future.
3
7
0
I just wanted to try to build a project with django. Therefore I have a (basic) question on how to manage such a project. Since I cannot find any guidelines or so on how to split a project into applications. Let's take a kind of SO as an example. Which applications would you use? I'd say there should be the applications "users" and "questions". But what if there was a topic system with static articles, too. Maybe they also could receive votes. How to build the apps structure then? One app for "questions", "votes" and "topics" or just one app "content"? I have no idea what to do. Maybe it's because I know not very much about Django yet, but I'm interested either...
How do you manage your Django applications?
0.119427
0
0
1,848
384,471
2008-12-21T13:37:00.000
0
0
0
0
python,mysql,python-3.x
385,225
9
false
0
0
You're probably better off using Python 2.x at the moment. It's going to be a while before all Python packages are ported to 3.x, and I expect writing a library or application with 3.x at the moment would be quite frustrating.
1
36
0
So, looking for a mysql-db-lib that is compatible with py3k/py3.0/py3000, any ideas? Google turned up nothing.
MySQL-db lib for Python 3.x?
0
1
0
43,916
384,761
2008-12-21T18:22:00.000
3
1
1
0
.net,com,ironpython
385,013
1
true
0
0
Answering my own post.. :-) com_error may be replaced by System.Runtime.InteropServices.COMException The pywintypes.Time may be replaced by System.DateTime, (DATE in IDispatch interface) Still, if anybody knows about any good documentation on IronPython, COM interoperability and moving from pywin32 to .net, please respond..
1
1
0
I have some old python code that uses the pywin32 extensions. Starting out with .net, I would like to port it to ironpython. The old python code uses things like pythoncom.com_error, pywintypes.Time and interfaces a COM module that implements the IDispatch interface. Does the .net libraries of ironpython have all I need for communicating with the COM module? Specifically, does it have something to replace com_error and Time? Thanks.
Does ironpython have libraries that replace the pywin32 extensions?
1.2
0
0
887
385,403
2008-12-22T02:25:00.000
1
1
1
0
javascript,python,language-agnostic,lua,oop
3,958,261
5
false
0
0
Classical inheritance is inherently flawed in terms of flexibility, in that we are saying "this object is of this type and no other". Some languages introduce multiple inheritance to alleviate this, but multiple inheritance has its own pitfalls, and so the benefits of pure composition over inheritance (which, in a statically typed language, is a runtime rather than a compile time mechanism) become clear. Taking the concept of composition to this "pure" level, we can eliminate classical inheritance altogether along with static typing. By composing objects at runtime and using them as blueprints (the prototypal approach), we need never concern ourselves with boxing objects too tightly through inheritance, nor burden ourselves with the issues inherent in multiple inheritance approaches. So prototypal means much more flexible development of modules. Of course, it's quite another thing to say it's EASY to develop without static typing. IMO, it is not.
2
10
0
I come from classes object orientation languages and recently I have been learning those fancy dynamic languages (JavaScript, Python and Lua) and I want some tips about how to use OO in those languages. It would be useful to know the pitfalls and the shortcomings of such approach and the advantages compared to traditional OO. The general notion that I got is that prototype based OO is basically programming with objects but no standard on how to use them whereas in normal OO there is a fixed predefined way to make and use objects. In summary, what is the good, the bad and the ugly parts of such approach?
Prototype based object orientation. The good, the bad and the ugly?
0.039979
0
0
4,736
385,403
2008-12-22T02:25:00.000
0
1
1
0
javascript,python,language-agnostic,lua,oop
385,417
5
false
0
0
Okay, first of all, the prototype model isn't all that different in reality; Smalltalk uses a similar sort of scheme; the class is an object with the classes methods. Looked at from the class POV, a class is really the equivalence class of objects with the same data, and all the same methods; you can look at adding a method to a prototype as creating a new subclass. The implementation is simple, but makes it very difficult to do effective typechecking.
2
10
0
I come from classes object orientation languages and recently I have been learning those fancy dynamic languages (JavaScript, Python and Lua) and I want some tips about how to use OO in those languages. It would be useful to know the pitfalls and the shortcomings of such approach and the advantages compared to traditional OO. The general notion that I got is that prototype based OO is basically programming with objects but no standard on how to use them whereas in normal OO there is a fixed predefined way to make and use objects. In summary, what is the good, the bad and the ugly parts of such approach?
Prototype based object orientation. The good, the bad and the ugly?
0
0
0
4,736
385,572
2008-12-22T04:35:00.000
0
0
1
0
python,string,int,bit,casting
386,651
5
false
0
0
I don't think this can necessarily be answered well without more information. As others have said, there are only int and long for integers in python -- the language doesn't adhere to the bit-width and signedness archetypes of lower-level programming languages. If you're operating completely within python, then you're probably asking the wrong question. There's likely a better way to do what you need. If you are interoperating with, for instance, C code, or over the network, then there are ways to do this, and it looks like the answer to your previous posting covered that avenue pretty handily.
2
24
0
I need to convert strings in Python to other types such as unsigned and signed 8, 16, 32, and 64 bit ints, doubles, floats, and strings. How can I do this?
Typecasting in Python
0
0
0
101,991
385,572
2008-12-22T04:35:00.000
3
0
1
0
python,string,int,bit,casting
386,116
5
false
0
0
The following types -- for the most part -- don't exist in Python in the first place. In Python, strings are converted to ints, longs or floats, because that's all there is. You're asking for conversions that aren't relevant to Python in the first place. Here's the list of types you asked for and their Python equivalent. unsigned and signed int 8 bits, int unsigned and signed int 16 bits, int unsigned and signed int 32 bits, unsigned: long, signed int unsigned and signed int 64 bits, long double, float float, float string, this is what you had to begin with I don't know what the following are, so I don't know a Python equivalent. unsigned and signed 8 bit, unsigned and signed 16 bit, unsigned and signed 32 bit, unsigned and signed 64 bit. You already have all the conversions that matter: int(), long() and float().
2
24
0
I need to convert strings in Python to other types such as unsigned and signed 8, 16, 32, and 64 bit ints, doubles, floats, and strings. How can I do this?
Typecasting in Python
0.119427
0
0
101,991
386,655
2008-12-22T16:23:00.000
2
1
1
0
python,performance,optimization,rewrite
386,689
19
false
0
0
I used to prototype lots of things in python for doing things like log processing. When they didn't run fast enough, I'd rewrite them in ocaml. In many cases, the python was fine and I was happy with it. In some cases, as it started approaching 23 hours to do a days' logs, I'd get to rewriting. :) I would like to point out that even in those cases, I may have been better off just profiling the python code and finding a happier python implementation.
14
47
0
Has anyone ever had code in Python, that turned out not to perform fast enough? I mean, you were forced to choose another language because of it? We are investigating using Python for a couple of larger projects, and my feeling is that in most cases, Python is plenty fast enough for most scenarios (compared to say, Java) because it relies on optimized C routines. I wanted to see if people had instances where they started out in Python, but ended up having to go with something else because of performance. Thanks.
Python Performance - have you ever had to rewrite in something else?
0.02105
0
0
8,929
386,655
2008-12-22T16:23:00.000
19
1
1
0
python,performance,optimization,rewrite
386,702
19
false
0
0
This is a much more difficult question to answer than people are willing to admit. For example, it may be that I am able to write a program that performs better in Python than it does in C. The fallacious conclusion from that statement is "Python is therefore faster than C". In reality, it may be because I have much more recent experience in Python and its best practices and standard libraries. In fact no one can really answer your question unless they are certain that they can create an optimal solution in both languages, which is unlikely. In other words "My C solution was faster than my Python solution" is not the same as "C is faster than Python" I'm willing to bet that Guido Van Rossum could have written Python solutions for adam and Dustin's problems that performed quite well. My rule of thumb is that unless you are writing the sort of application that requires you to count clock cycles, you can probably achieve acceptable performance in Python.
14
47
0
Has anyone ever had code in Python, that turned out not to perform fast enough? I mean, you were forced to choose another language because of it? We are investigating using Python for a couple of larger projects, and my feeling is that in most cases, Python is plenty fast enough for most scenarios (compared to say, Java) because it relies on optimized C routines. I wanted to see if people had instances where they started out in Python, but ended up having to go with something else because of performance. Thanks.
Python Performance - have you ever had to rewrite in something else?
1
0
0
8,929
386,655
2008-12-22T16:23:00.000
1
1
1
0
python,performance,optimization,rewrite
393,185
19
false
0
0
A month ago i had this little program written in Python (for work) that analyzes logs. When then number of log files grew, the program begun to be very slow and i thought i could rewrite it in Java. I was very interesting. It took a whole day to migrate the same algorithm from Python to Java. At the end of the day, a few benchmark trials showed me clearly that the Java program was some 20% / 25% slower than its Python counterpart. It was a surprise to me. Writing for the second time the algorithm also showed me that some optimization was possible. So in two hours i completely rewrote the whole thing in Python and it was some 40% faster than the original Python implementation (hence orders of time faster than the Java version I had). So: Python is a slow language but still it can be faster, for certain tasks, that other supposedly faster languages If you have to spend time writing something in a language whose execution is faster but whose development time is slower (most languages), consider using the same time to analyze the problem, search for libraries, profile and then write better Python code.
14
47
0
Has anyone ever had code in Python, that turned out not to perform fast enough? I mean, you were forced to choose another language because of it? We are investigating using Python for a couple of larger projects, and my feeling is that in most cases, Python is plenty fast enough for most scenarios (compared to say, Java) because it relies on optimized C routines. I wanted to see if people had instances where they started out in Python, but ended up having to go with something else because of performance. Thanks.
Python Performance - have you ever had to rewrite in something else?
0.010526
0
0
8,929
386,655
2008-12-22T16:23:00.000
2
1
1
0
python,performance,optimization,rewrite
386,706
19
false
0
0
You can always write parts of your application in Python. Not every component is equally important for performance. Python integrates easily with C++ natively, or with Java via Jython, or with .NET via IronPython. By the way, IronPython is more efficient than the C implementation of Python on some benchmarks.
14
47
0
Has anyone ever had code in Python, that turned out not to perform fast enough? I mean, you were forced to choose another language because of it? We are investigating using Python for a couple of larger projects, and my feeling is that in most cases, Python is plenty fast enough for most scenarios (compared to say, Java) because it relies on optimized C routines. I wanted to see if people had instances where they started out in Python, but ended up having to go with something else because of performance. Thanks.
Python Performance - have you ever had to rewrite in something else?
0.02105
0
0
8,929
386,655
2008-12-22T16:23:00.000
7
1
1
0
python,performance,optimization,rewrite
386,999
19
false
0
0
Not so far. I work for a company that has a molecular simulation engine and a bunch of programs written in python for processing the large multi-gigabyte datasets. All of our analysis software is now being written in Python because of the huge advantages in development flexibility and time. If something is not fast enough we profile it with cProfile and find the bottlenecks. Usually there are one or two functions which take up 80 or 90% of the runtime. We then take those functions and rewrite them in C, something which Python makes dead easy with its C API. In many cases this results in an order of magnitude or more speedup. Problem gone. We then go on our merry way continuing to write everything else in Python. Rinse and repeat... For entire modules or classes we tend to use Boost.python, it can be a bit of a bear but ultimately works well. If it's just a function or two, we sometimes inline it with scipy.weave if the project is already using scipy.
14
47
0
Has anyone ever had code in Python, that turned out not to perform fast enough? I mean, you were forced to choose another language because of it? We are investigating using Python for a couple of larger projects, and my feeling is that in most cases, Python is plenty fast enough for most scenarios (compared to say, Java) because it relies on optimized C routines. I wanted to see if people had instances where they started out in Python, but ended up having to go with something else because of performance. Thanks.
Python Performance - have you ever had to rewrite in something else?
1
0
0
8,929
386,655
2008-12-22T16:23:00.000
7
1
1
0
python,performance,optimization,rewrite
386,770
19
false
0
0
While at uni we were writing a computer vision system for analysing human behaviour based on video clips. We used python because of the excellent PIL, to speed up development and let us get easy access to the image frames we'd extracted from the video for converting to arrays etc. For 90% of what we wanted it was fine and since the images were reasonably low resolution the speed wasn't bad. However, a few of the processes required some complex pixel-by-pixel computations as well as convolutions which are notoriously slow. For these particular areas we re-wrote the innermost parts of the loops in C and just updated the old Python functions to call the C functions. This gave us the best of both worlds. We had the ease of data access that python provides, which enabled to develop fast, and then the straight-line speed of C for the most intensive computations.
14
47
0
Has anyone ever had code in Python, that turned out not to perform fast enough? I mean, you were forced to choose another language because of it? We are investigating using Python for a couple of larger projects, and my feeling is that in most cases, Python is plenty fast enough for most scenarios (compared to say, Java) because it relies on optimized C routines. I wanted to see if people had instances where they started out in Python, but ended up having to go with something else because of performance. Thanks.
Python Performance - have you ever had to rewrite in something else?
1
0
0
8,929
386,655
2008-12-22T16:23:00.000
2
1
1
0
python,performance,optimization,rewrite
386,752
19
false
0
0
I've been working for a while now, developing an application that operate on large structured data, stored in several-gigabytes-thick-database and well, Python is good enough for that. The application has GUI client with a multitude of controls (lists, trees, notebooks, virtual lists and more), and a console server. We had some performance issues, but those were mostly related more to poor algorithm design or database engine limitations (we use Oracle, MS-SQL, MySQL and had short romance with BerkeleyDB used for speed optimizations) than to Python itself. Once you know how to use standard libraries (written in C) properly you can make your code really quick. As others say - any computation intensive algorithm, code that depends on bit-stuffing, some memory constrained computation - can be done in raw C/C++ for CPU/memory saving (or any other tricks), but the whole user interaction, logging, database handling, error handling - all that makes the application actually run, can be written in Python and it will maintain responsiveness and decent overall performance.
14
47
0
Has anyone ever had code in Python, that turned out not to perform fast enough? I mean, you were forced to choose another language because of it? We are investigating using Python for a couple of larger projects, and my feeling is that in most cases, Python is plenty fast enough for most scenarios (compared to say, Java) because it relies on optimized C routines. I wanted to see if people had instances where they started out in Python, but ended up having to go with something else because of performance. Thanks.
Python Performance - have you ever had to rewrite in something else?
0.02105
0
0
8,929
386,655
2008-12-22T16:23:00.000
0
1
1
0
python,performance,optimization,rewrite
1,900,043
19
false
0
0
I generally don't rewrite to C before I : profile rewrite with bette algorithms (generally this is enough) rewrite python code with low level performance in mind (but never to the point of having non pythonic / non readable code) spend some time rechecking a library cannot do this (first in stdlib, or an external lib) tried psyco / other implementations (rarely achieves to get a REAL speed boost in my case) Then sometimes I created a shared library to do heavy matrix computation code (which couldn't be done with numarray) and called it with ctypes : simple to write/build/test a .so / dll in pure C, simple to encapsulate the C to python function (ie. you don't if you use basic datatypes since ctypes does all the work of calling the right arguments for you) and certainly fast enough then .
14
47
0
Has anyone ever had code in Python, that turned out not to perform fast enough? I mean, you were forced to choose another language because of it? We are investigating using Python for a couple of larger projects, and my feeling is that in most cases, Python is plenty fast enough for most scenarios (compared to say, Java) because it relies on optimized C routines. I wanted to see if people had instances where they started out in Python, but ended up having to go with something else because of performance. Thanks.
Python Performance - have you ever had to rewrite in something else?
0
0
0
8,929
386,655
2008-12-22T16:23:00.000
2
1
1
0
python,performance,optimization,rewrite
3,122,149
19
false
0
0
Yes, twice: An audio DSP application I wound up completely rewriting in C++ because I couldn't get appropriate performance in Python; I don't consider the Python implementation wasted because it let me prototype the concept very easily, and the C++ port went smoothly because I had a working reference implementaton. A procedural graphic rendering project, where generating large 2D texture maps in Python was taking a long time; I wrote a C++ DLL and used ctypes/windll to use it from Python.
14
47
0
Has anyone ever had code in Python, that turned out not to perform fast enough? I mean, you were forced to choose another language because of it? We are investigating using Python for a couple of larger projects, and my feeling is that in most cases, Python is plenty fast enough for most scenarios (compared to say, Java) because it relies on optimized C routines. I wanted to see if people had instances where they started out in Python, but ended up having to go with something else because of performance. Thanks.
Python Performance - have you ever had to rewrite in something else?
0.02105
0
0
8,929
386,655
2008-12-22T16:23:00.000
1
1
1
0
python,performance,optimization,rewrite
387,988
19
false
0
0
No, I've never had to rewrite. In fact, I started using Python in Maya 8.5. Before Maya 8, the only scripting language available was the built in MEL (Maya Expression Language). Python is actually faster than the built in language that it wraps. Python's ability to work with complex data types also made it faster because MEL can only store single dimensional arrays (and no pointers). This would require multi-dimensional arrays be faked by either using multiple parallel arrays, or by using slow string concatenation.
14
47
0
Has anyone ever had code in Python, that turned out not to perform fast enough? I mean, you were forced to choose another language because of it? We are investigating using Python for a couple of larger projects, and my feeling is that in most cases, Python is plenty fast enough for most scenarios (compared to say, Java) because it relies on optimized C routines. I wanted to see if people had instances where they started out in Python, but ended up having to go with something else because of performance. Thanks.
Python Performance - have you ever had to rewrite in something else?
0.010526
0
0
8,929
386,655
2008-12-22T16:23:00.000
2
1
1
0
python,performance,optimization,rewrite
501,942
19
false
0
0
I am developing in python for several years now. Recently i had to list all files in a directory and build a struct with filename, size, attributes and modification date. I did this with os.listdir and os.stat. The code was quite fast, but the more entries in the directories, the slower my code became comapred to other filemanagers listing the same directory, so i rewrote the code using SWIG/C++ and was really surprised how much faster the code was.
14
47
0
Has anyone ever had code in Python, that turned out not to perform fast enough? I mean, you were forced to choose another language because of it? We are investigating using Python for a couple of larger projects, and my feeling is that in most cases, Python is plenty fast enough for most scenarios (compared to say, Java) because it relies on optimized C routines. I wanted to see if people had instances where they started out in Python, but ended up having to go with something else because of performance. Thanks.
Python Performance - have you ever had to rewrite in something else?
0.02105
0
0
8,929
386,655
2008-12-22T16:23:00.000
1
1
1
0
python,performance,optimization,rewrite
393,200
19
false
0
0
I once had to write a pseudo-random number generator for a simulator. I wrote it in Python first, but Python proved to be way too slow; I ended up rewriting it in C, and even that was slow, but not nearly as slow as Python. Luckily, it's fairly easy to bridge Python and C, so I was able to write the PRNG as a C module and still write the rest of the simulator in Python.
14
47
0
Has anyone ever had code in Python, that turned out not to perform fast enough? I mean, you were forced to choose another language because of it? We are investigating using Python for a couple of larger projects, and my feeling is that in most cases, Python is plenty fast enough for most scenarios (compared to say, Java) because it relies on optimized C routines. I wanted to see if people had instances where they started out in Python, but ended up having to go with something else because of performance. Thanks.
Python Performance - have you ever had to rewrite in something else?
0.010526
0
0
8,929
386,655
2008-12-22T16:23:00.000
4
1
1
0
python,performance,optimization,rewrite
390,700
19
false
0
0
This kind of question is likely to start a religious war among language people so let me answer it a little bit differently. For most cases in today's computing environments your choice of programming language should be based on what you can program efficiently, program well and what makes you happy not the performance characteristics of the language. Also, optimization should generally be the last concern when programming any system. The typical python way to do things is to start out writing your program in python and then if you notice the performance suffering profile the application and attempt to optimize the hot-spots in python first. If optimizing the python code still isn't good enough the areas of the code that are weighing you down should be re-written as a python module in C. If even after all of that your program isn't fast enough you can either change languages or look at scaling up in hardware or concurrency. That's the long answer, to answer your question directly; no, python (sometimes with C extensions) has been fast enough for everything I need it to do. The only time I really dip into C is to get access to stuff that donesn't have python bindings. Edit: My background is a python programmer at a large .com where we use python for everything from the front-end of our websites all the way down to all the back-office systems. Python is very much an enterprise-grade language.
14
47
0
Has anyone ever had code in Python, that turned out not to perform fast enough? I mean, you were forced to choose another language because of it? We are investigating using Python for a couple of larger projects, and my feeling is that in most cases, Python is plenty fast enough for most scenarios (compared to say, Java) because it relies on optimized C routines. I wanted to see if people had instances where they started out in Python, but ended up having to go with something else because of performance. Thanks.
Python Performance - have you ever had to rewrite in something else?
0.04208
0
0
8,929
386,655
2008-12-22T16:23:00.000
5
1
1
0
python,performance,optimization,rewrite
386,909
19
false
0
0
Whenever I find a Python bottleneck, I rewrite that code in C as a Python module. For example, I have some hardware that sends image pixels as 4-byte 0RGB. Converting 8M from 0RGB to RGB in Python takes too long so I rewrote it as a Python module. Writing Python (or other higher level languages) is much faster than writing in C so I use Python until I can't.
14
47
0
Has anyone ever had code in Python, that turned out not to perform fast enough? I mean, you were forced to choose another language because of it? We are investigating using Python for a couple of larger projects, and my feeling is that in most cases, Python is plenty fast enough for most scenarios (compared to say, Java) because it relies on optimized C routines. I wanted to see if people had instances where they started out in Python, but ended up having to go with something else because of performance. Thanks.
Python Performance - have you ever had to rewrite in something else?
0.052583
0
0
8,929
387,606
2008-12-22T22:37:00.000
0
0
0
0
python,sql,user-input
387,800
4
false
0
0
To start with, treat the barcode input as plain old text. It has been quite a while since I worked with barcode scanners, but I doubt they have changed that much, the older ones used to just piggyback on the keyboard input, so from a programming perspective, the net result was a stream of characters in the keyboard buffer, either typed or scanned made no difference. If the device you are targeting differs from that, you will need to write something to deal with that before you get to the database query. If you have one of the devices to play with, plug it in, start notepad, start scanning some barcodes and see what happens.
3
1
0
I need to design a program using python that will ask the user for a barcode. Then, using this barcode, it will search a mysql to find its corresponding product. I am a bit stuck on how to get started. Does anyone have any tips for me?
Using user input to find information in a Mysql database
0
1
0
4,847
387,606
2008-12-22T22:37:00.000
1
0
0
0
python,sql,user-input
387,622
4
false
0
0
A barcode is simply a graphical representation of a series of characters (alphanumeric) So if you have a method for users to enter this code (a barcode scanner), then its just an issue of querying the mysql database for the character string.
3
1
0
I need to design a program using python that will ask the user for a barcode. Then, using this barcode, it will search a mysql to find its corresponding product. I am a bit stuck on how to get started. Does anyone have any tips for me?
Using user input to find information in a Mysql database
0.049958
1
0
4,847
387,606
2008-12-22T22:37:00.000
0
0
0
0
python,sql,user-input
387,694
4
false
0
0
That is a very ambiguous question. What you want can be done in many ways depending on what you actually want to do. How are your users going to enter the bar code? Are they going to use a bar code scanner? Are they entering the bar code numbers manually? Is this going to run on a desktop/laptop computer or is it going to run on a handheld device? Is the bar code scanner storing the bar codes for later retrieval or is it sending them directly to the computer. Will it send them through a USB cable or wireless?
3
1
0
I need to design a program using python that will ask the user for a barcode. Then, using this barcode, it will search a mysql to find its corresponding product. I am a bit stuck on how to get started. Does anyone have any tips for me?
Using user input to find information in a Mysql database
0
1
0
4,847
387,619
2008-12-22T22:40:00.000
7
0
0
0
python,mysql
387,932
4
true
0
0
"However, opening and closing the connection with each update seems more 'neat'. " It's also a huge amount of overhead -- and there's no actual benefit. Creating and disposing of connections is relatively expensive. More importantly, what's the actual reason? How does it improve, simplify, clarify? Generally, most applications have one connection that they use from when they start to when they stop.
3
2
0
I'm writing a script in python which basically queries WMI and updates the information in a mysql database. One of those "write something you need" to learn to program exercises. In case something breaks in the middle of the script, for example, the remote computer turns off, it's separated out into functions. Query Some WMI data Update that to the database Query Other WMI data Update that to the database Is it better to open one mysql connection at the beginning and leave it open or close the connection after each update? It seems as though one connection would use less resources. (Although I'm just learning, so this is a complete guess.) However, opening and closing the connection with each update seems more 'neat'. Functions would be more stand alone, rather than depend on code outside that function.
Mysql Connection, one or many?
1.2
1
0
1,201
387,619
2008-12-22T22:40:00.000
2
0
0
0
python,mysql
387,735
4
false
0
0
I don't think that there is "better" solution. Its too early to think about resources. And since wmi is quite slow ( in comparison to sql connection ) the db is not an issue. Just make it work. And then make it better. The good thing about working with open connection here, is that the "natural" solution is to use objects and not just functions. So it will be a learning experience( In case you are learning python and not mysql).
3
2
0
I'm writing a script in python which basically queries WMI and updates the information in a mysql database. One of those "write something you need" to learn to program exercises. In case something breaks in the middle of the script, for example, the remote computer turns off, it's separated out into functions. Query Some WMI data Update that to the database Query Other WMI data Update that to the database Is it better to open one mysql connection at the beginning and leave it open or close the connection after each update? It seems as though one connection would use less resources. (Although I'm just learning, so this is a complete guess.) However, opening and closing the connection with each update seems more 'neat'. Functions would be more stand alone, rather than depend on code outside that function.
Mysql Connection, one or many?
0.099668
1
0
1,201
387,619
2008-12-22T22:40:00.000
1
0
0
0
python,mysql
389,364
4
false
0
0
Useful clues in S.Lott's and Igal Serban's answers. I think you should first find out your actual requirements and code accordingly. Just to mention a different strategy; some applications keep a pool of database (or whatever) connections and in case of a transaction just pull one from that pool. It seems rather obvious you just need one connection for this kind of application. But you can still keep a pool of one connection and apply following; Whenever database transaction is needed the connection is pulled from the pool and returned back at the end. (optional) The connection is expired (and of replaced by a new one) after a certain amount of time. (optional) The connection is expired after a certain amount of usage. (optional) The pool can check (by sending an inexpensive query) if the connection is alive before handing it over the program. This is somewhat in between single connection and connection per transaction strategies.
3
2
0
I'm writing a script in python which basically queries WMI and updates the information in a mysql database. One of those "write something you need" to learn to program exercises. In case something breaks in the middle of the script, for example, the remote computer turns off, it's separated out into functions. Query Some WMI data Update that to the database Query Other WMI data Update that to the database Is it better to open one mysql connection at the beginning and leave it open or close the connection after each update? It seems as though one connection would use less resources. (Although I'm just learning, so this is a complete guess.) However, opening and closing the connection with each update seems more 'neat'. Functions would be more stand alone, rather than depend on code outside that function.
Mysql Connection, one or many?
0.049958
1
0
1,201
390,263
2008-12-23T22:37:00.000
0
0
1
0
python,excel,pywin32
390,304
2
false
0
0
I tried this with Excel 2007 and VBA. It is giving correct value. 1) Try pasting this value in a new excel workbook 2) Press Alt + F11. Gets you to VBA Editor. 3) Press Ctrl + G. Gets you to immediate window. 4) In the immediate window, type ?cells("a1").Value here "a1" is the cell where you have pasted the value. I am doubting that the cell has some value or character due to which it is interpreted this way. Post your observations here.
1
1
0
I am using python to read a currency value from excel. The returned from the range.Value method is a tuple that I don't know how to parse. For example, the cell appears as $548,982, but in python the value is returned as (1, 1194857614). How can I get the numerical amount from excel or how can I convert this tuple value into the numerical value? Thanks!
Interpreting Excel Currency Values
0
1
0
586
390,409
2008-12-23T23:43:00.000
1
1
0
0
python,debugging,templates,jinja2,mako
390,603
6
false
1
0
I break them down into pieces, and then reassemble the pieces when I've found the problem. Not good, but it's really hard to tell what went wrong in a big, complex template.
1
41
0
So far I've found it impossible to produce usable tracebacks when Mako templates aren't coded correctly. Is there any way to debug templates besides iterating for every line of code?
How do you debug Mako templates?
0.033321
0
0
10,962
390,867
2008-12-24T06:07:00.000
2
0
0
0
python,wxpython,wxwidgets,model-view-controller,project-organization
390,912
4
false
0
1
As Mark stated you should make a new class that handles things like this. The ideal layout of code when using something like wxWidgets is the model view controller where the wxFrame class only has the code needed to display items and all the logic and business rules are handled by other class that interact with the wxFrame. This way you can change logic and business rules with out having to change your interface and change (or swap) your interface with out having to change your logic and business rules.
3
1
0
I'm starting out with wxPython and have been working my way through every tutorial and example I can get my hands on. I've run into a slight problem, however, and it has to do with the wx.App versus the wx.Frame and which should contain specific methods. Just about every example I've seen don't go much beyond layouts/sizers and event handling, none really tackle project organization of a wxPython project. For example, I have a method that gets a list of folders. The way most examples would deal with this would be to stick the method right in the frame class. This method has the potential to be used in several other parts of the application, so it would make more sense to store it at the application class level. How should I organize and call "universal" methods like these so that I don't clutter up my frame classes. UPDATE: To clarify, the "list of folders" was just an example, my actual method does a lot more work. What I'm saying is I have code that isn't Frame-specific. If I had this in the application class, what is the best way to call it from and event method in my frame. I'm looking for actual project organization techniques, not programming fundamentals.
Calling Application Methods from a wx Frame Class
0.099668
0
0
1,063
390,867
2008-12-24T06:07:00.000
2
0
0
0
python,wxpython,wxwidgets,model-view-controller,project-organization
394,333
4
true
0
1
Your classes that inherit from wxWidgets/wxPython data types should not implement any business logic. wxWidgets is a GUI library, so any subclasses of wxApp or wxFrame should remain focused on GUI, that is on displaying the interface and being responsive to user actions. The code that does something useful should be separated from wx, as you can decide later to use it in some web or console application and you don't want to create wxApp object in such case. You can also decide later on to move some computations to separate 'worker threads', while your GUI will be the 'main thread' - responsive, and repainted properly during long lasting computations. Last but not least - the classes that encapsulate your logic might tend to grow during projects lifetime. If they're mixed with your GUI classes they will grow faster, and finally they become so complex that you're almost unable to debug them... While having them separated leads to clean code when you don't mix bugs in logic with bugs in GUI (refreshing/layout/progress bar etc.). Such approach has another nice feature - ability to split work among GUI-people and logic-people, which can do their work without constant conflicts.
3
1
0
I'm starting out with wxPython and have been working my way through every tutorial and example I can get my hands on. I've run into a slight problem, however, and it has to do with the wx.App versus the wx.Frame and which should contain specific methods. Just about every example I've seen don't go much beyond layouts/sizers and event handling, none really tackle project organization of a wxPython project. For example, I have a method that gets a list of folders. The way most examples would deal with this would be to stick the method right in the frame class. This method has the potential to be used in several other parts of the application, so it would make more sense to store it at the application class level. How should I organize and call "universal" methods like these so that I don't clutter up my frame classes. UPDATE: To clarify, the "list of folders" was just an example, my actual method does a lot more work. What I'm saying is I have code that isn't Frame-specific. If I had this in the application class, what is the best way to call it from and event method in my frame. I'm looking for actual project organization techniques, not programming fundamentals.
Calling Application Methods from a wx Frame Class
1.2
0
0
1,063
390,867
2008-12-24T06:07:00.000
0
0
0
0
python,wxpython,wxwidgets,model-view-controller,project-organization
390,887
4
false
0
1
In a proper OOP design, this would be independent or part of a filesystem class - it wouldn't be part of the app or the frame.
3
1
0
I'm starting out with wxPython and have been working my way through every tutorial and example I can get my hands on. I've run into a slight problem, however, and it has to do with the wx.App versus the wx.Frame and which should contain specific methods. Just about every example I've seen don't go much beyond layouts/sizers and event handling, none really tackle project organization of a wxPython project. For example, I have a method that gets a list of folders. The way most examples would deal with this would be to stick the method right in the frame class. This method has the potential to be used in several other parts of the application, so it would make more sense to store it at the application class level. How should I organize and call "universal" methods like these so that I don't clutter up my frame classes. UPDATE: To clarify, the "list of folders" was just an example, my actual method does a lot more work. What I'm saying is I have code that isn't Frame-specific. If I had this in the application class, what is the best way to call it from and event method in my frame. I'm looking for actual project organization techniques, not programming fundamentals.
Calling Application Methods from a wx Frame Class
0
0
0
1,063
391,879
2008-12-24T17:23:00.000
22
0
1
0
python,project-organization
391,916
4
false
0
0
"As is good practice I want to put them in a separate file each. " This is not actually a very good practice. You should design modules that contain closely-related classes. As a practical matter, no class actually stands completely alone. Generally classes come in clusters or groups that are logically related.
1
46
0
I'm starting a Python project and expect to have 20 or more classes in it. As is good practice I want to put them in a separate file each. However, the project directory quickly becomes swamped with files (or will when I do this). If I put a file to import in a folder I can no longer import it. How do I import a file from another folder and will I need to reference to the class it contains differently now that it's in a folder? Thanks in advance
Organising my Python project
1
0
0
21,485
392,160
2008-12-24T20:13:00.000
20
1
1
0
python,metaclass
392,442
21
false
0
0
Let's start with Tim Peter's classic quote: Metaclasses are deeper magic than 99% of users should ever worry about. If you wonder whether you need them, you don't (the people who actually need them know with certainty that they need them, and don't need an explanation about why). Tim Peters (c.l.p post 2002-12-22) Having said that, I have (periodically) run across true uses of metaclasses. The one that comes to mind is in Django where all of your models inherit from models.Model. models.Model, in turn, does some serious magic to wrap your DB models with Django's ORM goodness. That magic happens by way of metaclasses. It creates all manner of exception classes, manager classes, etc. etc. See django/db/models/base.py, class ModelBase() for the beginning of the story.
4
148
0
I have a friend who likes to use metaclasses, and regularly offers them as a solution. I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order. Being able to use metaclasses has caused a lot of people in a lot of places to use classes as some kind of second rate object, which just seems disastrous to me. Is programming to be replaced by meta-programming? The addition of class decorators has unfortunately made it even more acceptable. So please, I am desperate to know your valid (concrete) use-cases for metaclasses in Python. Or to be enlightened as to why mutating classes is better than mutating objects, sometimes. I will start: Sometimes when using a third-party library it is useful to be able to mutate the class in a certain way. (This is the only case I can think of, and it's not concrete)
What are some (concrete) use-cases for metaclasses?
1
0
0
32,950
392,160
2008-12-24T20:13:00.000
8
1
1
0
python,metaclass
7,057,480
21
false
0
0
A reasonable pattern of metaclass use is doing something once when a class is defined rather than repeatedly whenever the same class is instantiated. When multiple classes share the same special behaviour, repeating __metaclass__=X is obviously better than repeating the special purpose code and/or introducing ad-hoc shared superclasses. But even with only one special class and no foreseeable extension, __new__ and __init__ of a metaclass are a cleaner way to initialize class variables or other global data than intermixing special-purpose code and normal def and class statements in the class definition body.
4
148
0
I have a friend who likes to use metaclasses, and regularly offers them as a solution. I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order. Being able to use metaclasses has caused a lot of people in a lot of places to use classes as some kind of second rate object, which just seems disastrous to me. Is programming to be replaced by meta-programming? The addition of class decorators has unfortunately made it even more acceptable. So please, I am desperate to know your valid (concrete) use-cases for metaclasses in Python. Or to be enlightened as to why mutating classes is better than mutating objects, sometimes. I will start: Sometimes when using a third-party library it is useful to be able to mutate the class in a certain way. (This is the only case I can think of, and it's not concrete)
What are some (concrete) use-cases for metaclasses?
1
0
0
32,950
392,160
2008-12-24T20:13:00.000
5
1
1
0
python,metaclass
5,330,521
21
false
0
0
The only legitimate use-case of a metaclass is to keep other nosy developers from touching your code. Once a nosy developer masters metaclasses and starts poking around with yours, throw in another level or two to keep them out. If that doesn't work, start using type.__new__ or perhaps some scheme using a recursive metaclass. (written tongue in cheek, but I've seen this kind of obfuscation done. Django is a perfect example)
4
148
0
I have a friend who likes to use metaclasses, and regularly offers them as a solution. I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order. Being able to use metaclasses has caused a lot of people in a lot of places to use classes as some kind of second rate object, which just seems disastrous to me. Is programming to be replaced by meta-programming? The addition of class decorators has unfortunately made it even more acceptable. So please, I am desperate to know your valid (concrete) use-cases for metaclasses in Python. Or to be enlightened as to why mutating classes is better than mutating objects, sometimes. I will start: Sometimes when using a third-party library it is useful to be able to mutate the class in a certain way. (This is the only case I can think of, and it's not concrete)
What are some (concrete) use-cases for metaclasses?
0.047583
0
0
32,950
392,160
2008-12-24T20:13:00.000
2
1
1
0
python,metaclass
7,058,179
21
false
0
0
This is a minor use, but... one thing I've found metaclasses useful for is to invoke a function whenever a subclass is created. I codified this into a metaclass which looks for an __initsubclass__ attribute: whenever a subclass is created, all parent classes which define that method are invoked with __initsubclass__(cls, subcls). This allows creation of a parent class which then registers all subclasses with some global registry, runs invariant checks on subclasses whenever they are defined, perform late-binding operations, etc... all without have to manually call functions or to create custom metaclasses that perform each of these separate duties. Mind you, I've slowly come to realize the implicit magicalness of this behavior is somewhat undesirable, since it's unexpected if looking at a class definition out of context... and so I've moved away from using that solution for anything serious besides initializing a __super attribute for each class and instance.
4
148
0
I have a friend who likes to use metaclasses, and regularly offers them as a solution. I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order. Being able to use metaclasses has caused a lot of people in a lot of places to use classes as some kind of second rate object, which just seems disastrous to me. Is programming to be replaced by meta-programming? The addition of class decorators has unfortunately made it even more acceptable. So please, I am desperate to know your valid (concrete) use-cases for metaclasses in Python. Or to be enlightened as to why mutating classes is better than mutating objects, sometimes. I will start: Sometimes when using a third-party library it is useful to be able to mutate the class in a certain way. (This is the only case I can think of, and it's not concrete)
What are some (concrete) use-cases for metaclasses?
0.019045
0
0
32,950
392,217
2008-12-24T21:05:00.000
3
0
0
0
python,html,ruby,layout
392,243
2
false
1
0
Scriptor, I think what you likely are looking for might be something in JavaScript more then Ruby or Python. I mean - the positions and sizes are essentially going to be determined by the rendering engine (the browser). You might consider using something like jQuery to loop through all of your desired objects - outputting the name of the object (like the DIV's ID) and the height and width of that item. So, for what it's worth I'd look at jQuery if I was in your position and the height() and width() methods. You never know - there may already be a jQuery plugin.
2
3
0
I'm looking for a library in Ruby or Python that would take some HTML and CSS as the input and return data that contains the positions and sizes of the elements. If it helps, I don't need the info for all the elements but just the major divs of the page.
Is there a Ruby/Python HTML reflow/layout library?
0.291313
0
0
488
392,217
2008-12-24T21:05:00.000
-1
0
0
0
python,html,ruby,layout
392,412
2
false
1
0
Both Ruby and Python have a Regex library. Why not search for things like /width=\"(\d+)px\"/ and /height:(\d+)px/. Use $1 to find the value in the group. I'm not a regex expert and I'm doing this from memory, so refer to any of the tutorials on the net for the correct syntax and variable usage, but that's where to start. Good luck, bsperlinus
2
3
0
I'm looking for a library in Ruby or Python that would take some HTML and CSS as the input and return data that contains the positions and sizes of the elements. If it helps, I don't need the info for all the elements but just the major divs of the page.
Is there a Ruby/Python HTML reflow/layout library?
-0.099668
0
0
488
392,624
2008-12-25T08:25:00.000
-1
1
1
1
c#,java,python,networking
393,963
15
false
0
0
C++ and Java are quite slow compared to C. The language should be a tool but not a crutch.
9
15
0
I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really like the language (that "self" stuff grossed me out). I know that C++ is the language for the job in terms of performance, but I hate it. I don't want to deal with its sloppy syntax and I like my hand to be held by managed languages. This brings me to C# and Java, but I am open to other languages. I love the simplicity of .NET, but I was wondering if, speed wise, this would be good for the job. Keep in mind since this will be deployed on a Linux server, it would be running on the Mono framework - not sure if that matters. I know that Java is syntax-wise very similar to .Net, but my experience with it is limited. Are there any frameworks out there for it or anthing to ease in the development? Please help me and my picky self arrive on a solution. UPDATE: I didn't mean to sound so picky, and I really don't think I was. The only language I really excluded was C++, Python I don't like because of the scalability problem. I know that there are ways of communicating between processes, but if I have an 8 core server, why should I need to make 8 processes? Is there a more elegant solution?
Good language to develop a game server in?
-0.013333
0
0
16,457
392,624
2008-12-25T08:25:00.000
0
1
1
1
c#,java,python,networking
392,874
15
false
0
0
What are your objectives? Not the creation of the game itself, but why are you creating it? If you're doing it to learn a new language, then pick the one that seems the most interesting to you (i.e., the one you most want to learn). If it is for any other reason, then the best language will be the one that you already know best and enjoy using most. This will allow you to focus on working out the game logic and getting something up and running so that you can see progress and remain motivated to continue, rather than getting bogged down in details of the language you're using and losing interest. If your favorite language proves inadequate in some ways (too slow, not expressive enough, whatever), then you can rewrite the problem sections in a more suitable language when issues come up - and you won't know the best language to address the specific problems until you know what the problems end up being. Even if your chosen language proves entirely unsuitable for final production use and the whole thing has to be rewritten, it will give you a working prototype with tested game logic, which will make dealing with the new language far easier.
9
15
0
I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really like the language (that "self" stuff grossed me out). I know that C++ is the language for the job in terms of performance, but I hate it. I don't want to deal with its sloppy syntax and I like my hand to be held by managed languages. This brings me to C# and Java, but I am open to other languages. I love the simplicity of .NET, but I was wondering if, speed wise, this would be good for the job. Keep in mind since this will be deployed on a Linux server, it would be running on the Mono framework - not sure if that matters. I know that Java is syntax-wise very similar to .Net, but my experience with it is limited. Are there any frameworks out there for it or anthing to ease in the development? Please help me and my picky self arrive on a solution. UPDATE: I didn't mean to sound so picky, and I really don't think I was. The only language I really excluded was C++, Python I don't like because of the scalability problem. I know that there are ways of communicating between processes, but if I have an 8 core server, why should I need to make 8 processes? Is there a more elegant solution?
Good language to develop a game server in?
0
0
0
16,457
392,624
2008-12-25T08:25:00.000
3
1
1
1
c#,java,python,networking
392,831
15
false
0
0
More details about this game server might help folks better answer your question. Is this a game server in the sense of something like a Counter Strike dedicated server which sits in the background and hosts multiplayer interactions or are you writing something which will be hosted on an HTTP webserver? Personally, if it were me, I'd be considering Java or C++. My personal preference and skill set would probably lead me towards C++ because I find Java clumsy to work with on both platforms (moreso on Linux) and don't have the confidence that C# is ready for prime-time in Linux yet. That said, you also need to have a pretty significant community hammering on said server before performance of your language is going to be so problematic. My advise would be to write it in whatever language you can at the moment and if your game grows to be of sufficient size, invest in a rewrite at that time.
9
15
0
I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really like the language (that "self" stuff grossed me out). I know that C++ is the language for the job in terms of performance, but I hate it. I don't want to deal with its sloppy syntax and I like my hand to be held by managed languages. This brings me to C# and Java, but I am open to other languages. I love the simplicity of .NET, but I was wondering if, speed wise, this would be good for the job. Keep in mind since this will be deployed on a Linux server, it would be running on the Mono framework - not sure if that matters. I know that Java is syntax-wise very similar to .Net, but my experience with it is limited. Are there any frameworks out there for it or anthing to ease in the development? Please help me and my picky self arrive on a solution. UPDATE: I didn't mean to sound so picky, and I really don't think I was. The only language I really excluded was C++, Python I don't like because of the scalability problem. I know that there are ways of communicating between processes, but if I have an 8 core server, why should I need to make 8 processes? Is there a more elegant solution?
Good language to develop a game server in?
0.039979
0
0
16,457
392,624
2008-12-25T08:25:00.000
1
1
1
1
c#,java,python,networking
392,645
15
false
0
0
It may depend a lot on what language your "game logic" (you may know this term as "business logic") is best expressed in. For example, if the game logic is best expressed in Python (or any other particular language) it might be best to just write it in Python and deal with the performance issues the hard way with either multi-threading or clustering. Even though it may cost you a lot of time to get the performance you want out of Python it will be less that the time it will take you to express "player A now casts a level 70 Spell of darkness in the radius of 7 units effecting all units that have spoken with player B and .... " in C++. Something else to consider is what protocol you will be using to communicate with the clients. If you have a complex binary protocol C++ may be easier (esp. if you already had experience doing it before) while a JSON (or similar) may be easier to parse in Python. Yes, i know C++ and python aren't languages you are limited to (or even considering) but i'm refer to them generally here. Probably comes down to what language you are the best at. A poorly written program which you hated writing will be worse that one written in a language you know and enjoy, even if the poorly written program was in an arguable more powerful language.
9
15
0
I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really like the language (that "self" stuff grossed me out). I know that C++ is the language for the job in terms of performance, but I hate it. I don't want to deal with its sloppy syntax and I like my hand to be held by managed languages. This brings me to C# and Java, but I am open to other languages. I love the simplicity of .NET, but I was wondering if, speed wise, this would be good for the job. Keep in mind since this will be deployed on a Linux server, it would be running on the Mono framework - not sure if that matters. I know that Java is syntax-wise very similar to .Net, but my experience with it is limited. Are there any frameworks out there for it or anthing to ease in the development? Please help me and my picky self arrive on a solution. UPDATE: I didn't mean to sound so picky, and I really don't think I was. The only language I really excluded was C++, Python I don't like because of the scalability problem. I know that there are ways of communicating between processes, but if I have an 8 core server, why should I need to make 8 processes? Is there a more elegant solution?
Good language to develop a game server in?
0.013333
0
0
16,457
392,624
2008-12-25T08:25:00.000
2
1
1
1
c#,java,python,networking
392,764
15
false
0
0
You could as well use Java and compile the code using GCC to a native executable. That way you don't get the performance hit of the bytecode engine (Yes, I know - Java out of the box is as fast as C++. It must be just me who always measures a factor 5 performance difference). The drawback is that the GCC Java-frontend does not support all of the Java 1.6 language features. Another choice would be to use your language of choice, get the code working first and then move the performance critical stuff into native code. Nearly all languages support binding to compiled libraries. That does not solve your "python does not multithread well"-problem, but it gives you more choices.
9
15
0
I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really like the language (that "self" stuff grossed me out). I know that C++ is the language for the job in terms of performance, but I hate it. I don't want to deal with its sloppy syntax and I like my hand to be held by managed languages. This brings me to C# and Java, but I am open to other languages. I love the simplicity of .NET, but I was wondering if, speed wise, this would be good for the job. Keep in mind since this will be deployed on a Linux server, it would be running on the Mono framework - not sure if that matters. I know that Java is syntax-wise very similar to .Net, but my experience with it is limited. Are there any frameworks out there for it or anthing to ease in the development? Please help me and my picky self arrive on a solution. UPDATE: I didn't mean to sound so picky, and I really don't think I was. The only language I really excluded was C++, Python I don't like because of the scalability problem. I know that there are ways of communicating between processes, but if I have an 8 core server, why should I need to make 8 processes? Is there a more elegant solution?
Good language to develop a game server in?
0.02666
0
0
16,457
392,624
2008-12-25T08:25:00.000
18
1
1
1
c#,java,python,networking
392,911
15
false
0
0
I might be going slightly off-topic here, but the topic interests me as I have (hobby-wise) worked on quite a few game servers (MMORPG servers) - on others' code as well as mine. There is literature out there that will be of interest to you, drop me a note if you want some references. One thing that strikes me in your question is the want to serve a thousand users off a multithreaded application. From my humble experience, that does not work too well. :-) When you serve thousands of users you want a design that is as modular as possible, because one of your primary goals will be to keep the service as a whole up and running. Game servers tend to be rather complex, so there will be quite a few show-stopping bugs. Don't make your life miserable with a single point of failure (one application!). Instead, try to build multiple processes that can run on a multitude of hosts. My humble suggestion is the following: Make them independent, so a failing process will be irrelevant to the service. Make them small, so that the different parts of the service and how they interact are easy to grasp. Don't let users communicate with the gamelogic OR DB directly. Write a proxy - network stacks can and will show odd behaviour on different architectures when you have a multitude of users. Also make sure that you can later "clean"/filter what the proxies forward. Have a process that will only monitor other processes to see if they are still working properly, with the ability to restart parts. Make them distributable. Coordinate processes via TCP from the start or you will run into scalability problems. If you have large landscapes, consider means to dynamically divide load by dividing servers by geography. Don't have every backend process hold all the data in memory. I have ported a few such engines written in C++ and C# for hosts operating on Linux, FreeBSD and also Solaris (on an old UltraSparc IIi - yes, mono still runs there :). From my experience, C# is well fast enough, considering on what ancient hardware it operates on that sparc machine. The industry (as far as I know) tends to use a lot of C++ for the serving work and embeds scripting languages for the actual game logic. Ah, written too much already - way cool topic.
9
15
0
I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really like the language (that "self" stuff grossed me out). I know that C++ is the language for the job in terms of performance, but I hate it. I don't want to deal with its sloppy syntax and I like my hand to be held by managed languages. This brings me to C# and Java, but I am open to other languages. I love the simplicity of .NET, but I was wondering if, speed wise, this would be good for the job. Keep in mind since this will be deployed on a Linux server, it would be running on the Mono framework - not sure if that matters. I know that Java is syntax-wise very similar to .Net, but my experience with it is limited. Are there any frameworks out there for it or anthing to ease in the development? Please help me and my picky self arrive on a solution. UPDATE: I didn't mean to sound so picky, and I really don't think I was. The only language I really excluded was C++, Python I don't like because of the scalability problem. I know that there are ways of communicating between processes, but if I have an 8 core server, why should I need to make 8 processes? Is there a more elegant solution?
Good language to develop a game server in?
1
0
0
16,457
392,624
2008-12-25T08:25:00.000
7
1
1
1
c#,java,python,networking
392,650
15
false
0
0
What kind of performance do you need? twisted is great for servers that need lots of concurrency, as is erlang. Either supports massive concurrency easily and has facilities for distributed computing. If you want to span more than one core in a python app, do the same thing you'd do if you wanted to span more than one machine — run more than one process.
9
15
0
I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really like the language (that "self" stuff grossed me out). I know that C++ is the language for the job in terms of performance, but I hate it. I don't want to deal with its sloppy syntax and I like my hand to be held by managed languages. This brings me to C# and Java, but I am open to other languages. I love the simplicity of .NET, but I was wondering if, speed wise, this would be good for the job. Keep in mind since this will be deployed on a Linux server, it would be running on the Mono framework - not sure if that matters. I know that Java is syntax-wise very similar to .Net, but my experience with it is limited. Are there any frameworks out there for it or anthing to ease in the development? Please help me and my picky self arrive on a solution. UPDATE: I didn't mean to sound so picky, and I really don't think I was. The only language I really excluded was C++, Python I don't like because of the scalability problem. I know that there are ways of communicating between processes, but if I have an 8 core server, why should I need to make 8 processes? Is there a more elegant solution?
Good language to develop a game server in?
1
0
0
16,457
392,624
2008-12-25T08:25:00.000
21
1
1
1
c#,java,python,networking
392,627
15
false
0
0
I hate to say it, and I know I'm risking a down mod here, but it doesn't sound like there's a language out there for you. All programming languages have their quirks and programmers simply have to adapt to them. It's completely possible to write a working server in Python without classes (eliminating the "self" variable class references) and likewise just as easy to write C++ with clean syntax. If you're looking to deploy cross-platform and want to develop cross-platform as well, your best bet would probably be Java. It shorter development cycles than compiled languages like C and C++, but is higher performance (arguable, but I've always been anti-Java =P) than interpreted languages like Python and Perl and you don't have to work with unofficial implementations like Mono that may from time to time not support all of a language's features.
9
15
0
I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really like the language (that "self" stuff grossed me out). I know that C++ is the language for the job in terms of performance, but I hate it. I don't want to deal with its sloppy syntax and I like my hand to be held by managed languages. This brings me to C# and Java, but I am open to other languages. I love the simplicity of .NET, but I was wondering if, speed wise, this would be good for the job. Keep in mind since this will be deployed on a Linux server, it would be running on the Mono framework - not sure if that matters. I know that Java is syntax-wise very similar to .Net, but my experience with it is limited. Are there any frameworks out there for it or anthing to ease in the development? Please help me and my picky self arrive on a solution. UPDATE: I didn't mean to sound so picky, and I really don't think I was. The only language I really excluded was C++, Python I don't like because of the scalability problem. I know that there are ways of communicating between processes, but if I have an 8 core server, why should I need to make 8 processes? Is there a more elegant solution?
Good language to develop a game server in?
1
0
0
16,457
392,624
2008-12-25T08:25:00.000
2
1
1
1
c#,java,python,networking
392,844
15
false
0
0
The obvious candidates are Java and Erlang: Pro Java: ease of development good development environments stability, good stack traces well-known (easy to find experienced programmers, lots of libraries, books, ...) quite fast, mature VM Pro Erlang: proven in systems that need >99.9% uptime ability to have software updates without downtime scalable (not only multi-core, but also multi-machine) Contra Erlang: unfamiliar syntax and programming paradigm not so well known; hard to get experienced programmers for VM is not nearly as fast as java If your game server mainly works as a event dispatcher (with a bit of a database tucked on), Erlang's message-driven paradigm should be a good match. In this day and age, I would not consider using an unmanaged language (like C or C++); the marginal performance benefits simply aren't worth the hassle.
9
15
0
I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really like the language (that "self" stuff grossed me out). I know that C++ is the language for the job in terms of performance, but I hate it. I don't want to deal with its sloppy syntax and I like my hand to be held by managed languages. This brings me to C# and Java, but I am open to other languages. I love the simplicity of .NET, but I was wondering if, speed wise, this would be good for the job. Keep in mind since this will be deployed on a Linux server, it would be running on the Mono framework - not sure if that matters. I know that Java is syntax-wise very similar to .Net, but my experience with it is limited. Are there any frameworks out there for it or anthing to ease in the development? Please help me and my picky self arrive on a solution. UPDATE: I didn't mean to sound so picky, and I really don't think I was. The only language I really excluded was C++, Python I don't like because of the scalability problem. I know that there are ways of communicating between processes, but if I have an 8 core server, why should I need to make 8 processes? Is there a more elegant solution?
Good language to develop a game server in?
0.02666
0
0
16,457
392,784
2008-12-25T12:40:00.000
0
0
0
0
python,django,django-forms,django-templates
392,849
3
false
1
0
If the two forms are completely different, it will certainly not hurt to have them be handled by two different views. Otherwise, you may use the 'hidden input element' trick zacherates has touched upon. Or, you could always give each submit element a unique name, and differentiate in the view which form was submitted based on that.
1
5
0
I have two completely different forms in one template. How to process them in one view? How can I distinguish which of the forms was submitted? How can I use prefix to acomplish that? Or maybe it's better to write separate views? regards chriss
How to process two forms in one view?
0
0
0
7,720
393,629
2008-12-26T08:49:00.000
13
0
0
0
python,django,fastcgi
393,636
2
true
1
0
Let's start with the definition maxrequests: How many requests does a child server before being killed and a new one forked maxspare : Maximum number of spare processes to keep running minspare : Minimum number of spare processes to prefork maxchildren: Hard limit number of processes in prefork mode This means that you'll have at most maxchildren processes running at any given time in your webserver, each running for maxrequests requests. At server start you'll get minspare processes, which will keep growing until maxspare (or maxchildren) if more requests are coming. So, minspare lets you say how many concurrent requests are you expecting at a minimum (important to avoid the process creation if you start with one, it's good to start at, say 10), and maxspare lets you say how many concurrent requests will your server attend to at most (without compromising it's expected response time and so on. Needs a stress test to validate). And maxrequests is talking about the lifetime of each child, in case they cannot run forever due to any kind of constraint.
2
6
0
I'm running a Django app using FastCGI and lighttpd. Can somebody explain me what I should consider when deciding what value to use for maxrequests, maxspare, minspare, maxchildren? These options are not too well documented, but seem quite important. Don't just tell me what they do; I want to understand what implications they have and how I should decide on what values to use. Thanks.
What values to use for FastCGI maxrequests, maxspare, minspare, maxchildren?
1.2
0
0
5,068
393,629
2008-12-26T08:49:00.000
-1
0
0
0
python,django,fastcgi
393,649
2
false
1
0
Don't forget to coordinate your fcgi settings with your apache worker settings. I usually keep more apache workers around than fcgi workers... they are lighter weight and will wait for an available fcgi worker to free up to process the request if the concurrency reaches higher than my maxspare.
2
6
0
I'm running a Django app using FastCGI and lighttpd. Can somebody explain me what I should consider when deciding what value to use for maxrequests, maxspare, minspare, maxchildren? These options are not too well documented, but seem quite important. Don't just tell me what they do; I want to understand what implications they have and how I should decide on what values to use. Thanks.
What values to use for FastCGI maxrequests, maxspare, minspare, maxchildren?
-0.099668
0
0
5,068
394,465
2008-12-26T23:35:00.000
14
0
0
0
python,mod-wsgi
1,038,071
2
false
1
0
Be aware that technically speaking calling read() or read(-1) on wsgi.input is a violation of the WSGI specification even though Apache/mod_wsgi allows it. This is because the WSGI specification requires that a valid length argument be supplied. The WSGI specification also says you shouldn't read more data than is specified by the CONTENT_LENGTH. So, the code above may work in Apache/mod_wsgi but it isn't portable WSGI code and will fail on some other WSGI implementations. To be correct, determine request content length and supply that value to read().
1
15
0
This must be a very simple question, but I don't seem to be able to figure out. I'm using apache + mod_wsgi to host my python application, and I'd like to get the post content submitted in one of the forms -however, neither the environment values, nor sys.stdin contains any of this data. Mind giving me a quick hand? Edit: Tried already: environ["CONTENT_TYPE"] = 'application/x-www-form-urlencoded' (no data) environ["wsgi.input"] seems a plausible way, however, both environ["wsgi.input"].read(), and environ["wsgi.input"].read(-1) returns an empty string (yes, content has been posted, and environ["request_method"] = "post"
Python POST data using mod_wsgi
1
0
0
12,755
394,500
2008-12-27T00:25:00.000
1
0
1
1
python
394,548
4
false
0
0
I think there is something wrong in the design if you already have a file-like object if you want your data to end up in the subprocess. You should then arrange that they get written into the subprocess in the first place, rather than having them written into something else file-like first. Whoever is writing the data should allow the flexibility to specify the output stream, and that should be the subprocess pipe. Alternatively, if the writer insists on creating its own stream object, you should let it complete writing, and only then start the subprocess, feeding it from the result of first write. E.g. if it is a StringIO object, take its value after writing, and write it into the pipe; no need for thread synchronization here.
1
3
0
In the python program I'm writing, I've got a thread which iterates over a large structure in memory and writes it incrementally into a file-like object. I've got another thread which takes a file-like object and writes it to disk. Is there an easy way to connect the two, such that any data input from the first thread will be buffered for the second? Specifically, I'm trying to pass data to subprocess.Popen(). The process will read from stdin, but you cannot pass a "file-like" object to Popen because it calls stdin.fileno() and blows up unless you have a real file. Instead, you need to pass the PIPE argument to Popen, which allows you to use proc.stdin as a file-like object. But if you've already got a file-like object, there doesn't seem to be a great way to yolk the two of them together.
Is there a simple way in Python to create a file which can be written to in one thread and read in a different one?
0.049958
0
0
490
395,846
2008-12-28T04:52:00.000
0
0
0
0
python,sockets,ethernet,arp
503,144
2
false
0
0
You could use the OpenVPN tap to send arbitrary packets as if you where using raw sockets.
1
3
0
Is there any way to send ARP packet on Windows without the use of another library such as winpcap? I have heard that Windows XP SP2 blocks raw ethernet sockets, but I have also heard that raw sockets are only blocked for administrators. Any clarification here?
How do I send an ARP packet through python on windows without needing winpcap?
0
0
1
4,899
395,960
2008-12-28T07:56:00.000
1
1
0
0
php,python
397,669
5
false
1
0
Python web-apps tend to require more initial setup and development than the equivalent PHP site (particularly so for small sites). There also tend to be more reusable pieces for PHP (ie Wordpress as a blog). Configuring a server to run Python web-apps can be a difficult process, and not always well documented. PHP tends to be very easy to get running with Apache. Also, as PHP is very widely used and is heavily used by beginners, there tends to be very good documentation for it. However, Python is much more fun, and much more maintainable. It scales well (in development complexity terms, rather than traffic). Personally, I would also say that using Python tends to train you to solve problems in a better way. I am definitely a better developer for having learned the Pythonic way of doing things.
3
5
0
For those of you who have had the opportunity of writing web applications in PHP and then as an application server (eg. Python-based solutions like CherryPy or Pylons), in what context are application servers a better alternative to PHP? I tend to favor PHP simply because it's available on just about any web server (especially shared host), but I'm looking for other good reasons to make an informed choice. Thank you.
PHP vs. application server?
0.039979
0
0
1,413
395,960
2008-12-28T07:56:00.000
0
1
0
0
php,python
396,717
5
false
1
0
Using application servers like Pylons, Django, etc. require much more work to setup and deploy then PHP applications which are generally supported out of the box. I run a few Django apps and had to learn a bit of configuring apache with mod_python in order to get things to work. I put forth the effort because coding in python is much more enjoyable to me than PHP and after you get the Apache config right once you never really have to mess with it again. On another note, if you decide to go with a framework like Django, Rails, Pylons, .... they tend to solve a lot of small repetitive tasks that you would otherwise do on your own. But frameworks are their own huge topic of discussion.
3
5
0
For those of you who have had the opportunity of writing web applications in PHP and then as an application server (eg. Python-based solutions like CherryPy or Pylons), in what context are application servers a better alternative to PHP? I tend to favor PHP simply because it's available on just about any web server (especially shared host), but I'm looking for other good reasons to make an informed choice. Thank you.
PHP vs. application server?
0
0
0
1,413
395,960
2008-12-28T07:56:00.000
5
1
0
0
php,python
397,730
5
false
1
0
I have a feeling that some of the responses didn't address the initial question directly, so I decided to post my own. I understand that the question was about the difference between the mod_php deployment model and the application server deployment model. In simple words, PHP executes a given script on every request, and the application has no knowledge of what has happened before (unless it is emulated somehow). Moreover even the source code is being parsed on every request (unless you use a bytecode cache like APC). This process can be slow, especially if you have a framework with complex initialization. In contrast to this, the application server has to be started once, and then it waits for a request to be processed. The application server should clean up resources after every requests (allocated memory, open descriptors, etc.), it can also pool certain resources (like database connections) that can be reused between requests for extra performance. This later model (application server) is more efficient in most cases, but on the other hand more difficult to setup and maintain. It is also more demanding, as you have to pay more attention to the resources you utilize, in order to avoid resource leaks.
3
5
0
For those of you who have had the opportunity of writing web applications in PHP and then as an application server (eg. Python-based solutions like CherryPy or Pylons), in what context are application servers a better alternative to PHP? I tend to favor PHP simply because it's available on just about any web server (especially shared host), but I'm looking for other good reasons to make an informed choice. Thank you.
PHP vs. application server?
0.197375
0
0
1,413
396,455
2008-12-28T17:51:00.000
-1
0
0
0
python,postgresql,database,psycopg
675,865
4
false
0
0
using a MERGE statement instead of an INSERT one would solve your problem.
2
6
0
I am currently analyzing a wikipedia dump file; I am extracting a bunch of data from it using python and persisting it into a PostgreSQL db. I am always trying to make things go faster for this file is huge (18GB). In order to interface with PostgreSQL, I am using psycopg2, but this module seems to mimic many other such DBAPIs. Anyway, I have a question concerning cursor.executemany(command, values); it seems to me like executing an executemany once every 1000 values or so is better than calling cursor.execute(command % value) for each of these 5 million values (please confirm or correct me!). But, you see, I am using an executemany to INSERT 1000 rows into a table which has a UNIQUE integrity constraint; this constraint is not verified in python beforehand, for this would either require me to SELECT all the time (this seems counter productive) or require me to get more than 3 GB of RAM. All this to say that I count on Postgres to warn me when my script tried to INSERT an already existing row via catching the psycopg2.DatabaseError. When my script detects such a non-UNIQUE INSERT, it connection.rollback() (which makes ups to 1000 rows everytime, and kind of makes the executemany worthless) and then INSERTs all values one by one. Since psycopg2 is so poorly documented (as are so many great modules...), I cannot find an efficient and effective workaround. I have reduced the number of values INSERTed per executemany from 1000 to 100 in order to reduce the likeliness of a non-UNIQUE INSERT per executemany, but I am pretty certain their is a way to just tell psycopg2 to ignore these execeptions or to tell the cursor to continue the executemany. Basically, this seems like the kind of problem which has a solution so easy and popular, that all I can do is ask in order to learn about it. Thanks again!
Python-PostgreSQL psycopg2 interface --> executemany
-0.049958
1
0
7,742
396,455
2008-12-28T17:51:00.000
0
0
0
0
python,postgresql,database,psycopg
396,824
4
false
0
0
"When my script detects such a non-UNIQUE INSERT, it connection.rollback() (which makes ups to 1000 rows everytime, and kind of makes the executemany worthless) and then INSERTs all values one by one." The question doesn't really make a lot of sense. Does EVERY block of 1,000 rows fail due to non-unique rows? Does 1 block of 1,000 rows fail (out 5,000 such blocks)? If so, then the execute many helps for 4,999 out of 5,000 and is far from "worthless". Are you worried about this non-Unique insert? Or do you have actual statistics on the number of times this happens? If you've switched from 1,000 row blocks to 100 row blocks, you can -- obviously -- determine if there's a performance advantage for 1,000 row blocks, 100 row blocks and 1 row blocks. Please actually run the actual program with actual database and different size blocks and post the numbers.
2
6
0
I am currently analyzing a wikipedia dump file; I am extracting a bunch of data from it using python and persisting it into a PostgreSQL db. I am always trying to make things go faster for this file is huge (18GB). In order to interface with PostgreSQL, I am using psycopg2, but this module seems to mimic many other such DBAPIs. Anyway, I have a question concerning cursor.executemany(command, values); it seems to me like executing an executemany once every 1000 values or so is better than calling cursor.execute(command % value) for each of these 5 million values (please confirm or correct me!). But, you see, I am using an executemany to INSERT 1000 rows into a table which has a UNIQUE integrity constraint; this constraint is not verified in python beforehand, for this would either require me to SELECT all the time (this seems counter productive) or require me to get more than 3 GB of RAM. All this to say that I count on Postgres to warn me when my script tried to INSERT an already existing row via catching the psycopg2.DatabaseError. When my script detects such a non-UNIQUE INSERT, it connection.rollback() (which makes ups to 1000 rows everytime, and kind of makes the executemany worthless) and then INSERTs all values one by one. Since psycopg2 is so poorly documented (as are so many great modules...), I cannot find an efficient and effective workaround. I have reduced the number of values INSERTed per executemany from 1000 to 100 in order to reduce the likeliness of a non-UNIQUE INSERT per executemany, but I am pretty certain their is a way to just tell psycopg2 to ignore these execeptions or to tell the cursor to continue the executemany. Basically, this seems like the kind of problem which has a solution so easy and popular, that all I can do is ask in order to learn about it. Thanks again!
Python-PostgreSQL psycopg2 interface --> executemany
0
1
0
7,742