Skip to main content

GoStyle

Go syntax implementation in Python.

Installation

pip install gostyle

Threading Wrapper Like goRoutine

In GoLang, we can create parallel tasks via keyword go:

//GoLang
//...
go XXXX(arg1,arg2)
//...

In GoLang, the thread creating has following features:

  • The parameter passing is the same as the original function defined by user.
  • The original function is still usable as defined.

However, in Python creating a thread is stupid:

#Python
#...
t = threading.Thread(target=XXX, args=(arg1,arg2))
t.start()
#...

Usage with best compatibility:

import time
from gostyle import go, Chan
chan1 = Chan()
def test_thread(title:str):
    for cnt in range(10):
        chan1<=cnt
        time.sleep(1)
        print(title)
def chan_reader():
    while True :
        print(chan1())
# Start the thread 
go(test_thread)("Call")
chan_reader()

How To Use Word go in Python

If the function is self-defined, you can use decorator @gostyle.startable() like following:

import time
import gostyle
@gostyle.startable()
def test_thread(title:str):
    while True:
        time.sleep(1)
        print(title)
# Start the thread 
test_thread.start("Start")
# Note that the expression "test_thread('Normal')" can still run the original function in main thread.

Or, if the function is not a class/object method:

import time
import gostyle
@gostyle.destination()
def test_thread(title:str):
    while True:
        time.sleep(1)
        print(title)
# Start the thread 
gostyle.to.test_thread("Go To Destination")
# Note that the expression "test_thread('Normal')" can still run the original function in main thread.

Or:

import time
from gostyle import go
@go.goable()
def test_thread(title:str):
    while True:
        time.sleep(1)
        print(title)
# Start the thread 
go.test_thread("Go")
# Note that the expression "test_thread('Normal')" can still run the original function in main thread.

If the function is not self-defined(you can not add decorator to the function), or the function is a method of a class/object(the function you defined is hard to attach to "go"(same as "to") object in this package), you can use syntax like following:

import time
from gostyle import go
def test_thread(title:str):
    while True:
        time.sleep(1)
        print(title)
# Start the thread 
go(test_thread)("Call")

Run-Forever and Daemonize

The daemon parameter controls the deamon option in package threading. and the forever parameter lets you get rid of a while True: expression in the function you defined.

import time
from gostyle import go
def test_thread(title:str):
    # No Internal WHILE Here.
    time.sleep(1)
    print(title)
# Start the thread 
go(test_thread, forever=True)("Call Forever")
import time
import gostyle
@gostyle.startable(forever=True)
def test_thread(title:str):
    # No Internal WHILE Here.
    time.sleep(1)
    print(title)
# Start the thread 
test_thread.start("Start Loop")

Defer

In GoLang, defer is used to do things(usually cleaning-up) after a function returns.

How To Use in Python

Usage of decorator defer_inside:

from gostyle import defer_inside, defer
@defer_inside
def great_func():
    a = [1,2,3]
    b = 8
    defer(
        lambda : a.append(7),
        lambda : print(a),
        lambda : print(b)
    )
    a.append(9)
    return a,b
print(great_func())

Todos

Threading

Manage Threads started by gostyle Collect return values Single Instance support Yield Support Multithreading Support

Defer

Multi-times Defer Support

Queue

Queue Wrapper

Switch

...

Anonymous Functions

...

Metadata

Release files for gostyle 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gostyle 0.1.7
File Size Uploaded Provenance Actions
gostyle-0.1.7.tar.gz 3.6 kB Without provenance Details for gostyle-0.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gostyle 0.1.7
File Interpreter ABI Platform Actions
gostyle-0.1.7-py2.py3-none-any.whl Python 2, Python 3 none any Details for gostyle-0.1.7-py2.py3-none-any.whl

Total release size: 6.8 kB

Release files / gostyle-0.1.7.tar.gz

Download URL gostyle-0.1.7.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0bc540901e6e91e03988bc7e1fb865353dbd8e21fbb9aad6dbb26c1e93706186
BLAKE2b-256 checksum
How to use checksums
b14b796baedcb2ce2578972c5a7c878edee4acd5320c771a538aea89c5985d18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.6.6

Release files / gostyle-0.1.7-py2.py3-none-any.whl

Download URL gostyle-0.1.7-py2.py3-none-any.whl
Size 3.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5d7921b969c6a2f548fbb7a1323cd3543960b12893a420589cb527220dd0bf66
BLAKE2b-256 checksum
How to use checksums
a826d67880e36c822bb4c3b1e87f6a87cd4c15dd5617b2f9e1be3a3eabd56b53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.6.6

Security for gostyle 0.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page