Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>PicklingError: Can't pickle 'tkapp' object: &lt;tkapp object at 0x02A4C4F0&gt;</code> it looks like you might be trying to share/send an object to a subprocess, though implicitly, fundamentally the <code>multiprocessing</code> module by default, follows the <code>no share</code> methodology, meaning all objects are copied and sent to the sub process, with the goal of a far easier and safer <code>true</code> multithreading system, at the cost of performance among other things.</p> <p>Python uses the <code>pickle</code> module to serialize objects, and hence, if you can't serialize it you can't send it to a subprocess, theres a second requirement, the function must be importable, being that:</p> <pre><code>def start_server(self): self.logger.insert(END,"Starting process for client.") process=multiprocessing.Process(target=self.start_serving) process.start() </code></pre> <p>is a member function it really isn't importable, multiprocessing was trying to serialize all its member variables most of which couldn't be serialize, though this is a hunch.</p> <p>you could try this, placed outside the class.</p> <pre><code>def start_serving(): HOST, PORT = "localhost", 9999 server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler) server.serve_forever() </code></pre> <p>Assuming that you don't need any interprocess communication, if you do you can use a Queue from the multiprocessing module.</p> <p>this is how you start the subprocess.</p> <pre><code> def start_server(self): self.logger.insert(END,"Starting process for client.") self.process = multiprocessing.Process(target=start_serving) # make sure you keep a reference of the process. self.process.start() </code></pre> <p>then you can just kill the subprocess.</p> <pre><code>def stop_server(self): self.process.terminate() if __name__ == "__main__": Application().run() </code></pre> <p>Though I recommend you use the <code>ThreadingMixIn</code> instead of manually creating a subprocess, granted Im not sure if it uses <code>thread</code> or <code>process</code> being that <code>thread</code> don't actually run on multi-core machines due to the GIL while process do. I've tested it, unfortunately you cant kill the subprocess, <code>serve_forever</code> seems to be blocking...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload