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

Stop freezing main thread #638

Closed
wants to merge 136 commits into from
Closed

Stop freezing main thread #638

wants to merge 136 commits into from

Conversation

Ksengine
Copy link
Contributor

@Ksengine Ksengine commented Nov 4, 2020

stop freezing main thread

  • winforms Edge(supported, tested)
  • winforms CEF (supported, not tested)
  • winforms IE (supported, not tested)
  • gtk(supported, tested)
  • qt(supported, tested on linux only)
  • cocoa(not supported)

so,

  • test IE
  • test CEF
  • test qt on mac
  • develop cocoa

other developers are welcomed

automatically set webpage title as window title if user want
Automatically set title of webpage as window title
Automatically set icon of webpage as window icon
Automatically set icon of webpage as window icon
Automatically set icon of webpage as window icon
- multiprocessing added
- fixed threading
- added two keyword arguments to start method
    - block(default : True)
    - daemon(default : True)(works if block is False)

ex(block):-
```python
import webview
w = webview.create_window("ssss","https://www.google.com")
join = webview.start(block=False) # set block option to False( default:True )
print('free main thread')
# Some code
print('blocked main thread')
join() # join gui loop to main thread
print('free main thread') # this line works after gui loop ended
```

ex(block without join):-
```python
import webview
w = webview.create_window("ssss","https://www.google.com")
join = webview.start(block=False) # set block option to False( default:True )
print('free main thread')
# Some code
# program exits when no any code run and gui loop ended
```

ex(daemon):-
```python
import webview
w = webview.create_window("ssss","https://www.google.com")
join = webview.start(block=False, daemon=False) # set daemon option to False( default:True )
print('free main thread')
# Some code
# gui loop stops and exit program
```
`real_start` changed to `_start`
according to review of @r0x0r
stop freezing main thread using threading or multiprocessing
- remove multiprocessing arg of window class
- remove multiprocessing arg of _initialize
gtk only on linux
so used multiprocessing in `fork` method
returns thread to user
- modified current thread checker in create_window
- start returns the process if multiprocessing else None
- stop run app.exec_ if multiprocessing is True
- create fake Process class
- return fake process
sorry, i cant test this on mac
so it raises RuntimeError when multiprocessing
forgot ti import _multiprocessing
@Ksengine
Copy link
Contributor Author

@r0x0r It's ok. MacOS is working and tested(on github actions).

@github-actions
Copy link

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Jan 24, 2021
@Ksengine
Copy link
Contributor Author

Hi @r0x0r can you merge this.

@r0x0r
Copy link
Owner

r0x0r commented Jan 25, 2021

macOS no workie


[pywebview] Using Cocoa
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/roman/.vscode/extensions/ms-python.python-2021.1.502429796/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
    cli.main()
  File "/Users/roman/.vscode/extensions/ms-python.python-2021.1.502429796/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main
    run()
  File "/Users/roman/.vscode/extensions/ms-python.python-2021.1.502429796/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 285, in run_file
    runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/roman/Code/pywebview/examples/noblock.py", line 11, in <module>
    webview.start(block=False)
  File "/Users/roman/Code/pywebview/webview/__init__.py", line 127, in start
    return guilib.create_window(windows[0])
  File "/Users/roman/Code/pywebview/webview/platforms/mp_cocoa.py", line 74, in create_window
    windows[window.uid] = window
TypeError: list indices must be integers or slices, not str
Exception in thread Thread-7:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/roman/Code/pywebview/webview/platforms/mp_cocoa.py", line 64, in event_loop
    uid, event = event_queue.get()
  File "<string>", line 2, in get
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/managers.py", line 757, in _callmethod
    kind, result = conn.recv()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/connection.py", line 250, in recv
    buf = self._recv_bytes()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/connection.py", line 407, in _recv_bytes
    buf = self._recv(4)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/connection.py", line 383, in _recv
    raise EOFError
EOFError

@github-actions github-actions bot removed the stale label Jan 26, 2021
@github-actions
Copy link

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Feb 26, 2021
@Ksengine
Copy link
Contributor Author

Not stale

@github-actions github-actions bot removed the stale label Feb 27, 2021
@github-actions
Copy link

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Mar 29, 2021
@Ksengine
Copy link
Contributor Author

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

not stale

@github-actions github-actions bot removed the stale label Mar 30, 2021
@github-actions
Copy link

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Apr 29, 2021
@Ksengine
Copy link
Contributor Author

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Not stale

@github-actions github-actions bot removed the stale label Apr 30, 2021
@github-actions
Copy link

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label May 30, 2021
@Ksengine
Copy link
Contributor Author

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Not stale

@github-actions github-actions bot removed the stale label May 31, 2021
@github-actions
Copy link

github-actions bot commented Jul 1, 2021

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Jul 1, 2021
@github-actions
Copy link

github-actions bot commented Jul 7, 2021

The message to post on the pr when closing it. If none provided, will not comment when closing a pull requests.

@github-actions github-actions bot closed this Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants