-1

I am using python 2.7 and wxPython 2.8. I created a simple desktop application from which the user can start an HTTPServer created from the one builtin in python itself. Server is created in this way:

class Services(Thread):
    def __init__(self):
        Thread.__init__(self)

    def run(self):        
        http_server = BaseHTTPServer.HTTPServer(('',  9020)), RESTRequestHandler)        
        http_server.serve_forever()

in another piece of code I am using wxPrinting facilities to send HTML to printer so I am trying to reuse the same code in a rest api by doing the following (I am simplyfing):

def save(handler):
    manager = Manager('Samuel')
    wx.CallAfter(manager.do_print) #do_print is a method already used in another part of UI code and it is working)

if I don't use wx.CallAfter I got the error "only the main thread can process Windows messages".

But in this way the code seems working only in older windows system like Windows XP meanwhile in Windows 10 nothing happens.

HTTPServer has been created starting from https://gist.github.com/tliron/8e9757180506f25e46d9

3
  • Use a debugger or add print calls to check if save and do_print are called. Commented Jun 22, 2024 at 16:20
  • always put FULL error message (starting at word "Traceback") in question (not in comments) as text (not screenshot, not link to external portal). There are other useful information in the full error/traceback. It will be also more readable in question, and more people can see it - so more people may help. Commented Jun 22, 2024 at 21:10
  • most GUIs don't like to work with its widgets in separate threads and it needs to use queue to send information to main thread which will use this information to change/update widgets. And maybe Windows Messages also need to send information to main thread which will process it. Commented Jun 22, 2024 at 21:12

1 Answer 1

0

I fixed the issue by adding the wx.CallAfter(manager.do_print)

in a separate thread, like:

class Print(Thread):

    def run(self):  
        wx.CallAfter(manager.do_print)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.