question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

won't start with pythonw

See original GitHub issue

I wrote a simple service, and tried to deploy it on windows. I used pythonw.exe to start the script. But bottle won’t start. The process started and then quickly closed. But if I started it using python.exe, the process works fine. I think this might be a bug. The process won’t start even if I just imported bottle but not doing anything. The code looks like this. pythonw hello_world.py would start, and then quickly shutdown.

'''
hello_world.py
'''
import bottle
import time

if __name__ == '__main__':
    while True:
        print('Hello, world')
        time.sleep(2)

However, python hello_world.py will do the work, and if I comment import bottle out, pythonw will do the job too.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:18 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
nolanlcommented, May 12, 2019

Running a server on windows is a pretty common use case for pythonw.exe (the other is GUI apps). So there is good reason to run a bottle application without a console.

You can add:

sys.stdout = open('log.txt', 'w')
sys.stderr = open('err.txt', 'w')

to your app before you import bottle.

For some reason, nothing that gets written to stdout/stderr actually shows up in the files once bottle is imported, but aside from that it seems to work.

1reaction
josephernestcommented, Jul 26, 2022

@seth-c-stenzel For it to work, you have to do it in this order:

import sys
sys.stdout = open('stdout.log', 'a+', buffering=1)
sys.stderr = open('stderr.log', 'a+', buffering=1)

import bottle

app = bottle.Bottle()

@app.route('/')
def say_hello():
     return 'Hello, world!'

app.run(port=8888)

Can you confirm it works for you?

Read more comments on GitHub >

github_iconTop Results From Across the Web

pyw and pythonw does not run under Windows 7
pyw python file causes python.exe to show up under Task Manager. How do we troubleshoot the problem? The system is running Python 2.7....
Read more >
Issue 7817: Pythonw.exe fails to start - Python tracker
Pythonw.exe refuses to start on my Windows 7 x64 computer. ... has stopped working"), it simply doesn't open. python.exe works fine.
Read more >
How To Fix Annoying Pythonw.exe Errors [SOLVED] - Solvusoft
In most cases, pythonw.exe file problems are due to the file missing or being corrupted (malware / virus) and often seen at Python...
Read more >
[Resolved] Pythonw.exe has Stopped Working - Python Pool
Often, python developers face a challenging issue while resolving pythonw.exe stopped working issue. Here, we will be fixing that issue.
Read more >
Installation Successful, but pythonw and idle doesn't function
I also attempted to run "idle", with the following results: C:\Users\judy\AppData\Local\Programs\Python\Python35-32\Lib\idlelib>idle.py ** IDLE can't import ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found