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 9119743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:28:05+00:00 2026-06-17T05:28:05+00:00

My Code is: class Client(DirectObject, object): ”’ Clientclass. This class processes the keys which

  • 0

My Code is:

class Client(DirectObject, object):

'''
Clientclass. This class processes the keys which the user presses to the host and gets the data
from the host, which are to be set in a dummy version of the model
'''

seed= ""
id = None

def __init__(self, ip):
    '''
    This is the  constructor. It creates the ShowBase an starts both the process which processes the keys and the process 
    which takes in data from the host
    param: ip ip is a float which contains the ip adress of the host

    '''
    logging.getLogger(__name__).info("Clientobjekt erstellt")
    self.makw = mouseAndKeyWrapper.MouseAndKeyWrapper()
    time.sleep(5)      
    from modules.logic import game
    self.cprocess = threading.Thread(target = Client.workAsClient, args = (ip,self.makw))
    self.cprocess.start()
    time.sleep(5)
    while True:
        if Client.seed != "":
            break               
    game.seed = Client.seed
    game.initGame()
    game.initGameInstance()    
    game.start()    

    self.workShowBase()  
    game.myShowBase.run()



def workShowBase(self):

    '''
    workShowBase defines how to change values in keydict when keys are pressed and
    starts ShowBase process
    '''
    from modules.logic import game
    logging.getLogger(__name__).info("Showbase is working")
    game.myShowBase.accept("w", self.makw.setKeys, ["w",1])
    game.myShowBase.accept("a", self.makw.setKeys, ["a",1])
    game.myShowBase.accept("s", self.makw.setKeys, ["s",1])
    game.myShowBase.accept("d", self.makw.setKeys, ["d",1])
    game.myShowBase.accept("space", self.makw.setKeys, ["space",1])
    game.myShowBase.accept("w-up", self.makw.setKeys, ["w",0])
    game.myShowBase.accept("a-up", self.makw.setKeys, ["a",0])
    game.myShowBase.accept("s-up", self.makw.setKeys, ["s",0])
    game.myShowBase.accept("d-up", self.makw.setKeys, ["d",0])
    game.myShowBase.accept("space-up", self.makw.setKeys, ["space",0])
    #game.myShowBase.accept("mouse1",self.makw.setKeys,["mouse",1])
    #game.myShowBase.accept("mouse1-up",self.makw.setKeys,["mouse",0])





@staticmethod  
def workAsClient(ip, makw):
    '''
    This method contains the client thread, that is, the thread which sends data to the host and
    receives data from it - for this reason it has to be static
    param: ip ip is a float which contains the ip adress of the host
    '''
    logging.getLogger(__name__).info("Clientendlosschleife gestartet")
    from modules.logic import game
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
    s.connect((ip, 50001)) 
    seedSend = s.recv(4096)
    Client.seed =loads(seedSend)
    ID = s.recv(4096)
    Client.id = loads(ID)      
    makw.id = id
    keyThread = threading.Thread(target =Client.sendData, args = (makw,s))
    print("threadmade")
    keyThread.start()
    print("started")

@staticmethod    
def sendData(makw, sock):
    print("method")     
    while True:
        print("loop")
        dictToSend = dumps(makw,2)
        print("dumped")
        sock.sendall(dictToSend)
        print("sent")

That does work fine.

However, if I omitt “time.sleep(5)” in the constructor,
the thread which calls sendData is never ever made, let alone be started.
How can that be? Showbase technically should not interfere, being in another process!
Can I fix this?

  • 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-06-17T05:28:07+00:00Added an answer on June 17, 2026 at 5:28 am

    You should avoid using full active waiting that may consume all the resources letting no chance for other threads to work.

    So you may better try :

    while True:
            if Client.seed != "":
                break
            time.sleep(10)
    

    Indeed your secondary thread is launched but if all processing is consumed by your main thread in its infinite loop it will never have a chance to work, then never providing the seed for which the main thread is waiting => deadlock

    When you use sleep(5) you give a chance to the secondary thread to be scheduled and to produce the seed; then when latter the main thread is rescheduled it finds the seed, continues working and all is going as expected.

    But your workaround is very brittle because you have no guarantee that during the sleep of the main thread the other one will be scheduled.

    It works now in your development environment but may break later in production in another context.

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

Sidebar

Related Questions

I have an entity like this (any unnecessary code omitted): class Client{ private id;
Python and django newbie question, here is code: class Client(User) #some fields client=Client() client.save()
I am trying to code a number guessing class and client. The issue/problems I
I have this code: class LFSeq: # lazy infinite sequence with new elements from
I have this code: class SomeClass: @classmethod def func1(cls,arg1): #---Do Something--- @classmethod def func2(cls,arg1):
In java, I have my client class that have the code attr, and the
So I am coding this client/server program. This code is from the client side.
I have this simple server code: public class Server { public static void main(String[]
Given this Java code: class Account { private Integer number = 0; public synchronized
here is my code for the client class Program { static void Main(string[] args)

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.