Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.7 sh hangs when using in threads, forking and logging #81921

Closed
mzbuild mannequin opened this issue Aug 1, 2019 · 2 comments
Closed

Python 3.7 sh hangs when using in threads, forking and logging #81921

mzbuild mannequin opened this issue Aug 1, 2019 · 2 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@mzbuild
Copy link
Mannequin

mzbuild mannequin commented Aug 1, 2019

BPO 37740
Nosy @gpshead, @ned-deily, @ambv, @cagney

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2019-08-01.18:16:42.271>
created_at = <Date 2019-08-01.17:58:33.403>
labels = ['3.7', 'invalid', 'type-bug', 'library']
title = 'Python 3.7 sh hangs when using in threads, forking and logging'
updated_at = <Date 2019-08-01.18:16:42.267>
user = 'https://bugs.python.org/mzbuild'

bugs.python.org fields:

activity = <Date 2019-08-01.18:16:42.267>
actor = 'gregory.p.smith'
assignee = 'none'
closed = True
closed_date = <Date 2019-08-01.18:16:42.271>
closer = 'gregory.p.smith'
components = ['Library (Lib)']
creation = <Date 2019-08-01.17:58:33.403>
creator = 'mzbuild'
dependencies = []
files = []
hgrepos = []
issue_num = 37740
keywords = []
message_count = 2.0
messages = ['348869', '348870']
nosy_count = 7.0
nosy_names = ['gregory.p.smith', 'ned.deily', 'lukasz.langa', 'cagney', 'hugh', 'ebizzinfotech', 'mzbuild']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue37740'
versions = ['Python 3.7']

@mzbuild
Copy link
Mannequin Author

mzbuild mannequin commented Aug 1, 2019

Hi,
We use the sh module in a threaded context to execute shell commands. When we were migrating to python 3 from python 2 we encountered some commands hanging. We created a test script that recreates the issue we are seeing.
`import sh
import logging
import concurrent.futures.thread

def execmd(exe):
print(sh.ls())
execution_pool = concurrent.futures.thread.ThreadPoolExecutor(20)
i = 0
thread_results = []
while i<500:
i+= 1
thread_results.append(execution_pool.map(execmd, ['ls']))

execution_pool.shutdown()

When running this in python 3.7 it hangs but in python 3.6 it works fine. We think it is releated to this issue https://bugs.python.org/issue36533. Installing the latest 3.7.4 didn't fix the issue. The sh module uses logging and forking and the top script uses threading so we think there is a locking issue with 3.7. Any help would be great.

@mzbuild mzbuild mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 1, 2019
@gpshead
Copy link
Member

gpshead commented Aug 1, 2019

os.fork() cannot be safely used in an application that uses threads in any manner. This is not something Python can fix. This is a POSIX limitation.

The "sh" module on PyPI is incompatible with threaded applications on POSIX platforms due to its use of os.fork().

https://github.com/amoffat/sh/blob/master/sh.py#L1861

Raise this issue with them.

@gpshead gpshead closed this as completed Aug 1, 2019
@gpshead gpshead added the invalid label Aug 1, 2019
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant