Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6331893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:09:29+00:00 2026-05-24T18:09:29+00:00

I have a twisted server which does some long task for each request so

  • 0

I have a twisted server which does some “long” task for each request so i defer to thread each call. In each request i access a common resource, which gets altered during the process. Each request should start with the original data so i use deepcopy on the common resource (while invoking a lock acquire). It works, BUT i think it’s not fast enough. I have the feeling that deepcopy is slowing things a bit.

What suggestions do you have when dealing in a threaded twisted server with resources mutation ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:09:30+00:00Added an answer on May 24, 2026 at 6:09 pm

    If you like you could just synchronize access to the shared resource with threading.Lock just like you would in any other threaded program rather than copying it.

    Regardless, I think it’s worth benchmarking your code with and without the deepcopy and otherwise measuring to figure out how good/bad the performance really is before making optimizations. Perhaps the reason it is slow has nothing to do with deepcopy.

    EDIT regarding using locking: What I mean is that you can use more fine grained locking around this resource. I assume that your threads are doing more than accessing a shared resource. You can try to benefit from multiple threads doing work and then synchronize access to just the one “critical section” that involves writing to the shared resource. You might also investigate making your shared resource threadsafe. For example, if have a shared object, SillyExampleFriendsList:

    class SillyExampleFriendsList(object):
        """Just manipulates a couple lists"""
        def __init__(self):
           self._lock = threading.RLock()
           self._friends = []
           self._enemies = []
    
        def unfriend(self, x):
           # we lock here to ensure that we're never in a state where
           # someone might think 'x' is both our friend and our enemy.
           self._lock.acquire()
           self._friends.remove(x)
           self._enemies.append(x)
           self._lock.release()
    

    The point here is just that the above object could potentially be shared between multiple threads without deepcopy by careful use of locks. It’s not trivial to identify all the cases where this might be necessary and fine grained locking strategies can be more difficult to debug and still introduce overhead.

    That said, you may not need threads, locks, or deepcopy at all and without benchmarking your code it’s not clear if you have a performance problem that needs to be solved. I’m curious what makes you think that your code should be, or needs to be, faster?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XMPP server (likely — python, twisted, wokkel), which I prefer not
I have this twisted client, which connects with a twisted server having an index.
I have this simple Twisted Client which connects to a Twisted server & queries
I have program which has servers interacting with each other using Twisted's remote procedure
I have a Django application which sometimes needs to send some data through TCP
I have a project which is essentially a game server where users connect and
I have a client connected to a server using twisted. The client has a
I have an xmlrpc server using Twisted. The server has a huge amount of
I have created a simple Twisted based TCP server and Android client. I have
I have a game server written in python and twisted, and an old game

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.