473,769 Members | 6,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Advice: socket handling and threads

Hi people

Part of the reason I have started using Python (experience: 3 days) is that
I recognise the potential benefits in using it compared to writing C/C++
code. In particular, there are a couple of modules in an application that I
am writing that I have calculated will be up to ten times quicker to develop
(although it is hard to say at this stage), which is obviously quite
attractive.

The "problem" I have is relating to the existing C++ code I have. I've
started porting it to Python, so that the whole project will be in the same
language. The main aspects of my app that I am wondering about are socket
handling and multi-threading.

As far as I understand, Python can do everything that C/C++ can do with
sockets, plus there are the thread and threading modules which I believe are
equivalent to the pthreads module I have been using so far. My question is
this:

Is it sensible to port these sections of code to Python? Do I stand to gain
or lose by doing this... I doubt the performance difference will be
noticeable, and the only areas of the project that I would maybe consider
extending in C++ are to do with parsing (and to be honest I think it'll be
fine left in Python).

Finally there is the cherry on the cake in the form of cross-platform
compatibility. My C++ code only works on *nix (or cygwin) but as far as I
understand it, my threads and sockets should work fine on Windows and Mac
too, if done in Python...? (This is a CLI app not GUI by the way.)

Thoughts and general musings will be greatly appreciated (as will any
warnings of pitfalls I may encounter!)

Dan


Jul 18 '05 #1
1 1431
> Is it sensible to port these sections of code to Python? Do I stand to
gain or lose by doing this... I doubt the performance difference will be
noticeable, and the only areas of the project that I would maybe consider
extending in C++ are to do with parsing (and to be honest I think it'll be
fine left in Python).

Finally there is the cherry on the cake in the form of cross-platform
compatibility. My C++ code only works on *nix (or cygwin) but as far as I
understand it, my threads and sockets should work fine on Windows and Mac
too, if done in Python...? (This is a CLI app not GUI by the way.)

Thoughts and general musings will be greatly appreciated (as will any
warnings of pitfalls I may encounter!)


You should look into python twisted, a framework for networking. It has
plenty of features. You can easily write portable networking code that
makes use of select for dispatching, so you don't need to be multithreaded.
It also supports reactors that are multithreaded, but in my expirience
thats not necessary, as multithreading often is an excuse for easier
handling of blocking io - which you avoid by the underlying select-based
infrastructure.

I had a mult-threaded client-server-app that also involved the serial line -
porting it to twisted was easy and straighforward, and now I'm rid of all
threads - which leads to way lower system load while the performance is the
same.

Regards,

Diez
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2481
by: Phil Jenson | last post by:
I am try to evaluate the most efficient method of handling thousands of simultaneous TCP connects each of which remain connected to the server for hours and pass a small amount of data usually once a minute. The data received is logged in a SQL Server database. The only method I have found of reading each socket requires a thread for each connection which blocks waiting for data. This appears to be very inefficient as it will result in...
12
428
by: Phil Jenson | last post by:
I am try to evaluate the most efficient method of handling thousands of simultaneous TCP connects each of which remain connected to the server for hours and pass a small amount of data usually once a minute. The data received is logged in a SQL Server database. The only method I have found of reading each socket requires a thread for each connection which blocks waiting for data. This appears to be very inefficient as it will result in...
1
2819
by: shailesh333 | last post by:
I have written a small piece of code in 'c' for a simple server However when I call the socket function , it returns the value -1. What could be the problem?? Any help will be appreciated... Thanks in advance. I am using dev c++ as my IDE, and running the code in windows platform The code is as follows: #include<stdio.h>
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5309
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.